Geert Jan Bex

Geert Jan Bex

Since 2009 I'm an HPC consultant for the Flemish Supercomputer Center, doing support and training (also for PRACE and EuroCC). I've a PhD in physics and CS on topics in machine learning.

Location Belgium

Activity

  • @MiguelQuevedoB. That seems like a problem with your internet connection/configuration.

  • @SebastianMeyer Have a look at fibonacci/fibonacci.f90

  • @YueAnn You can make it explicitly abstract, that would be more consistent.

  • @HongPhucNguyen For scientific data HDF5 or netCDF (depending on your domain) are worth looking into. Both are platform and language-independent, and you get performance comparable to raw binary I/O with the added benefit of data organization, self-documentation and annotation.

  • @HongPhucNguyen Binding to Python is quite straightforward thank to f2py (in numpy).

    Glad you liked the course.

  • @HongPhucNguyen Not all best practices can be language-agnostic. Some are very specific to a language, either for technical reasons, or due to culture.

  • @AaronSanabria It depends a bit on the recursion depth, and the type of recursion. For low depth, it won't matter much. For tail recursion, the compiler will usually optimize.

  • @HongPhucNguyen associate is runtime, #define is compile time. Moreover, associate is a pure Fortran syntax feature, while #define requires you to run the preprocessor. The scope of the association is also clearly defined and imposed by the syntax. Although the same can be achieve using #undef, the burden would be on the developer.

  • @HongPhucNguyen Unless you do a lot of work to create a fast implementation of linked lists, remember that performance will suffer.

  • @AaronSanabria Welcome :)

  • @HongPhucNguyen Not sure what you are referring to. It seems there are only 2D examples in this section, no?

  • @HongPhucNguyen That implies they can be applied to arrays, i.e., called with an array as an argument, acting on each of the latter's elements.

  • @HongPhucNguyen I'd strongly disagree here. I'd suggest to always go with functions unless there is no alternative.

    Functions lend themselves more naturally to side-effect free programming, which is definitely best practice.

  • @HongPhucNguyen Have a look at the repository for many examples of modules. In short, it's intended for separation of concern and code reuse.

  • @HongPhucNguyen Indeed, always start by looking at the first error, don't be intimidated by a huge list. Solving that first one typically reduces the list considerably (or even completely).

  • @IanBoshoff There are a few things that can help to prevent this. Typically, the compiler will inline small procedures, i.e., it will insert the assembler instructions for the procedure at the site of the procedure call, hence avoiding the procedure call. Also, link-time optimization will consider multiple procedures and tries to find opportunities for...

  • @SebastianMeyer Indeed, that would work well, and there is nothing wrong doing it like this.

  • @ShainathKalamkar It is essentially a function that doesn't return a value, but acts on its arguments. In C/C++ that would be a function with return type void.

  • You might want to look at vTunes that is part of the OneAPI distribution. It is a GUI profiler that can also give you suggestions for and limits to optimizations and parallelizations (with threads, e.g., OpenMP).

  • @MélodieAngeletti Thanks for mentioning it, fixed.

  • @dg iso_fortran_env is a standard module (hence intrinsic, so that the compiler is to use the module supplied by the distribution, rather than a module with the same name that the developer might have created.
    It contains definitions of various constants such as INT32 and INT64, but also output_unit and error_unit.
    In this case, we care only about the INT32...

  • @MatthewRiruemkan Make sure to check the man page of ifort/ifx because the option to display warnings, for instance, differ from those of gfortran. Also note that for Intel Fortran -O2 optimization is the default, as opposed to gfortran.

  • @SophiaSimmons Have you ever used vim before, or are you new to it? In the latter case, vim has a learning curve, and I'd advise you to check out an online tutorial about it (there are many). vim is a very powerful editor and worth learning, but it takes some time to get proficient. If you prefer not to spend the effort, you'd better use anohter editor.

  • @IoannisStergiou Glad you enjoyed the training, hopefully it will be useful.

  • In Fortran arrays are first-class citizens, so many things you can do in MATLAB, you can also do in Fortran.

  • @LuzSilva Being familiar with a terminal interface such as Bash can help you in a number of ways. Data manipulation tasks are typically a lot easier to accomplish in such an environment. If you move to HPC infrastructure, you will have to have at least a nodding acquaintance with Bash or some other shell.

  • @AleksandraVisich Consider h5dcreate_f for creating a dataset (d), or h5gcreate_f for creating a group (g). The '_f' at the end of the names would be a suffix. Perhaps it would have been more clear if I'd used 'h5d'-prefix or 'h5g'-prefix?

  • @AleksandraVisich Depending on your domain, NetCDF can be the best storage format. I've some sample code in a Github repository that illustrates how to use NetCDF from Fortran.
    However, note that this code has not been updated in quite a while, so use with caution ;)
    https://github.com/gjbex/training-material/tree/master/DataStorage/NetCDF

  • @MohideenAnsar As far as I know, the Fortran specification doesn't say, so it is compiler-dependent. Most compilers also allow you to specify that on the command line. For me, best practice: always specify if you want to fix the precision, otherwise, leave it to compile time settings if it doesn't matter. Assume the minimum is the default in that case.

  • @AleksandraVisich In theory, yes, but nothing interesting happens outside of that region which is clear from the iteration condition.

  • @AleksandraVisich Which message?

  • @YassirWardi Indeed, I get a segmentation fault both with ifort and ifx. The backtrace shows that it has to do with te optional argument min_val. Intel Fortran compilers represent an optional argument that is not present by a null pointer, and you can not assign to that. The solution is to define a variable that will hold the minimum to be used, either...

  • @YassirWardi It works for me. Which Fortran ocmpiler are you using?

  • @LalitSyunary The answer to the question is 0, so that is correct. What is not correct is the implementation of the subroutine fill_array. It is always a good idea to compile with -fbounds-check while developing your code. The compiler will automatically insert code to verify that array indices are within bounds, throwing a runtime error if not.
    When you...

  • @GeorginoKalengTshikwand Glad you enjoyed the course.

  • @TahaSoomro Fortran I/O is weird ;) In short, the unit number plays a role similar to that of a file handle in other programming langauges such as Python.

  • @GeorginoKalengTshikwand I'm giving such a training (Python for HPC). The next iteration is not yet scheduled though.

  • @GeorginoKalengTshikwand Absolutely, we'll deal with those in week 5 (BLAS and Lapack).

  • @VittorioDiBona It limits what you make available from a module, the advantage is that you don't pollute the namespace with procedures or variables you don't need. It is good practice to do this.

  • @MatthewRiruemkan C++ is certainly useful. I actually run a training titled "Scientific C++" that focuses on C++ features that are useful for programming in the context of science and engineering.

  • @MatthewRiruemkan Relearning C++ might also make sense, but be aware that C++ has evolved considerably over the last 10 years. We moved from C++11 (in the best case, C++03 or C++98 in the worst) to C++20.
    Although you'd have to start from scratch in Python, I think that the investment is worthwhile anyway. There are quite a number of things I'd hesitate to...

  • @MatthewRiruemkan You could consider a basic programming course for Python. This is a nice language to complement Fortran anyway since it is more convenient for data processing/analytics and prototyping.

  • @MatthewRiruemkan That is of course fine. What happens exactly is likely to depend on the Fortran runtime, hence the compiler and its version. So your mileage may vary ;)

  • @MatthewRiruemkan This seems rather fishy: "iomsg-msg", you probably mean "iomsg=msg"?

  • @MatthewRiruemkan The problem is rather technical, and implementation (of the runtime, hence the compiler if you will). In the program unit, you have a print statement. This will be using the standard output unit, i.e., it will write the result to the screen. One of the values the print statement will write is the return value of the procedure you call,...

  • @MatthewRiruemkan A print in a function that is called in a print statement is a problem with some Fortran runtimes. In main, assign the value of the function to a variable, and print its value.

  • @MatthewRiruemkan At the time when this was recorded, WSL wasn't as mature and not widely available. For production, I worked with VMWare, but for about a year now I simply use WSL2 + containers for most things.

    So no, there is no need for a VM.

  • @GeorginoKalengTshikwand There are quite a number of excellent courses organized by PRACE, have a look at their training portal.

  • @MatthewRiruemkan If you like, but you don't need it (I don't use it).

  • I was using the default terminal of my Linux distribution (installed in a VM). As such you can use whatever you want, see the step on requirements.

  • @AnnEnnen Good point, in Fortran the situation is a little convoluted due to the distinction between subroutines and functions. A subroutine is considered to be pure in Fortran if it only modifies its arguments (or none at all). This would not be considered "pure" in the sense of the functional programming paradigm, hence the ambiguity.

  • @AnnEnnen The runtime will handle deallocation for you in many circumstances. However, sometimes it is better to do it yourself. In general, I deallocate myself, rather than rely on the runtime.

    The visibility modifiers will be discussed in one of the steps.

  • @GeorginoKalengTshikwand Exactly, a sloppy class hierarchy is counter-productive, and you will end up with code that is less flexible and harder to maintain while using object-orientation properly facilitates that.

    Of course, this is not specific to Fortran, that goes for any object-oriented programming language.

  • @GeorginoKalengTshikwand Many opinions you will hear or read on Fortran are based on Fortran 90, or Fortran 95 at best. Many people are ignorant that Fortran has evolved considerably since that time.

    It is one of the few programming languages that let you code high-level distributed programs without using external libraries (co-arrays, see week 5). This...

  • @AnnEnnen Since you refer to C and C++, I'll map the Fortran concepts to C++.

    A user-defined type is a struct in C++. As in C++, you can associate procedures with it, sort of like methods. You can also do dynamic memory allocation of arrays or user-defined types.

    Derived types can be compared to a C++ class that inherits from a parent class. It is a...

  • @GeorginoKalengTshikwand And with the added advantage that is was designed to do science, and to be easy to optimize.

  • @GeorginoKalengTshikwand Yes, that is possible, I didn't mention it for simplicity and clarity.

  • @IagoGiné You can set breakpoints in arbitrary files in GDB, e.g.,,
    b my_module.f90:my_procudure
    Of course, you need to build with -g to add debugging information to the executable.

  • @IagoGiné Interesting, I didn't notice this. However, it seems to be a problem with the GNU Fortran compiler (unless I'm missing something in the Fortran specification). The Intel compiler generates an application that runs without issues.
    The problem is in the allocate statement. Using the source argument with the "constructor" should ensure that the...

  • @GeorginoKalengTshikwand Don't forget that 2D arrays in Fortran are stored in column-major layout, as opposed to C where they are stored row-major.

  • @GeorginoKalengTshikwand Intel OneAPI can be used free of charge nowadays, and you can even have a docker container with the whole suite installed.

  • @GeorginoKalengTshikwand Unless I'm terminally confused here, 2 and 3 are printed, so I don't quite get what you mean.

  • @GeorginoKalengTshikwand How are you running the application? This will read from standard input, so if you don't feed standard input, the application will sit and wait forever, so call it with, e.g.,
    $ ./read_messy_data.exe < messy_data.txt

  • @IagoGiné-Vázquez You can create matrices for x0 and r as a meshgrid (see MATLAB or Python numpy), so that the result is a matrix of function values, so that the rows represent x0 values, and the columns r values.

  • @GeorginoKalengTshikwand The function is_leap_year is being called as an argument in the print statement. If you print from such a function, you create a deadlock. The print statement in the main program will lock the I/O stream, so the write statement in the is_leap_year function can not execute until the lock is released, which will never happen.
    This is...

  • @NinibethGibelliSarmientoHerrera Not unless you want to fork the repository to host your own copy of it on Github. To clone a repository (just get a local copy) you don't need an account (I think ;)

  • @IagoGiné-Vázquez The mask expression is optional, so you can, but don't have to specify a logical expression on the indices.

  • @AtulJadhav Sure, feel free to use any environment you feel comfortable with.

  • Geert Jan Bex replied to [Learner left FutureLearn]

    @varshafelsy You'd have to install WSL, it's not part of a default Windows installation. Google for installing WSL2 on your Windows version (10 or 11) and follow the instructions.

  • @IagoGiné-Vázquez If memory serves, that is 'vim-syntastic/syntastic'

  • Geert Jan Bex replied to [Learner left FutureLearn]

    @varshafelsy What directory are you in? You likely don't have write permissions there, or you executed the command twice (in that case, the directory may already exist, and mkdir will fail).

  • @yunus You're right, that's a typo. Thanks for pointing it out, I'll correct it.

  • @AjayRawat Good observations/questions and valid concerns. I'd personally not go as far as to say that Fortran starts to resemble C++. The OOP features of Fortran are more contained, and the syntax is simpler than C++. Of course, yes, if you add OOP to a language, it gets conceptually richer and hence more sophisticated. It will however also allow you to...

  • @AseemRajanKshirsagar They also offer better performance to math operations (although there are dragons with respect to performance).

  • @AseemRajanKshirsagar Frankly, I/O in Fortran is not really the nicest thing around.

  • @PaulP PRACE organizes excellent courses on MPI, OpenMP, CUDA and hybrid programming.

  • @PaulP It is, Python supports all the relevant bitwise operations.

  • @AseemRajanKshirsagar Yes, it is the syntax specification.

  • @PaulP It is mostly a matter of performance, and hence subject to benchmarking the two approaches for the application at hand.

  • @PaulP Textual I/O has the advantage that you can inspect results easily, but yes, performance can be suboptimal (by a significant factor).

  • @MohammadShamimHasanMandal Good question. My personal approach when learning a new language is to read the documentation on the standard library (intrinsic procedures in Fortran speak) diagonally. I don't try to remember details, but simply what functionality is available. When I need a procedure, I look up the details.

  • @PaulP You will like Fortran's user-defined types.

  • @PaulP Indeed, that is why indentation is still useful, even if it has no semantics in Python. Also, you can use, e.g., 'end if' to make sure things match up.

  • @Liviu-MarianIonita Glad you enjoyed it.

  • @EstherBendewr This is a linking error (ld), the flow of the build process is that both the Fortran file that contains the definition of the module and the file that contains the program unit are compiled, producing object files (.o files). The next steps is to link those two object files into an executable. The CMake files take care of this, so I'm guessing...

  • Geert Jan Bex replied to [Learner left FutureLearn]

    @enricospecogna You can start with just the compiler. If you want to build the code in the repository, you will need CMake as well.

  • @AshwinKumar I'm not sure I get what you mean. For performance (and multithreading) it is certainly best to use a BLAS implementation (either OpenBLAS or MKL or ...). It would be nice if the compiler could replace a call to matmul by a call to BLAS, but that is wishful thinking.

  • @RajKumarPaudel I can't reproduce that with the code in the GitHub repo, so I'm assuming you implemented this yourself?

  • @ChienNguyen Pascal is a descendant of Algol. It predates (official) Fortran pointers by two decades as pointers where introduced in Fortran 90 (although there were some extensions of Fortran 77 that already supported pointers).

  • Geert Jan Bex replied to [Learner left FutureLearn]

    @AshwinKumar We read from 'data.txt', we write to standard output. If you open a file to read, you can not write to it, and vice versa. It is possible though to open a file so that you can read and write to it, and in some situations that is of course very useful. We will see examples of that later.
    The fort.1027238656 file is likely a core dump, i.e., the...

  • @ChienNguyen An or would also help.

  • @AshwinKumar For large matrices, a good BLAS implementation (OpenBLAS or Intel's MKL) is still useful though.

  • @JacobAbdelfatah Normally, the scalar has the same type as the elements of the array, but of course, you could use an integer scalar and multiply it with a real array. Here, <op> can be any arithmetic operator.

  • @JacobAbdelfatah The sequence attribute indicates that the compiler should generate user-defined types with the elements in the order specified in the code. If you don't specify sequence, the compiler can reorder the elements to make better use of memory alignment, which can improve the performance of your code. So sequence should only be used when you...

  • @JacobAbdelfatah Note that the 2 is in front of the A, so it means 2 strings (A) to be printed. The number in front of the format specifier is the number of times it is repeated.

  • @JacobAbdelfatah We are printing entire arrays, the * indicates that the formatting code that is specified after it will be used for all array elements, regardless of the length of the array.

  • @ChienNguyen I've added code that works for me to the repository (https://github.com/gjbex/Fortran-MOOC/blob/master/source_code/text_io/format_str.f90), does that work for you?

  • @ChienNguyen Indeed, you are right, thanks for pointing it out.

  • @JacobAbdelfatah Be careful though, C++ boolean operators are lazy, those of Fortran are not.