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


  • @GuusLöhlefink In Python (using pandas) and R tables are also quite prominently present when analysing data.

  • @GuusLöhlefink The variable i is not redeclared in the block, so it is just the one from the outer scope. This would be the same behaviour as in, .e.g., C/C++.
    The syntax doesn't allow for an implicit none in a block. You can have implicit none only at the start of compilation units, e.g., program, function, subroutine, module.

  • @GuusLöhlefink I think it would make the code harder to read and look awkward, e.g.,
    if (x < y .and. y < z) then my_cond
    end my_cond
    Also, historically, labels in fortran where written in the first 5 columns of a line.

  • @GuusLöhlefink The point of case is that it is less general than if ... elseif .. else... This allows the compiler to generate faster code.
    I learned that two decades ago when I was writing a compiler in Java, the performance difference was significant.

  • @JulioMendez Elemental functions always work elementwise, regardless of the array's rank. Consider a 2x2 array:
    1 3
    2 4
    When you apply an elemental function f, you get
    f(1) f(3)
    f(2) f(4)

  • @TarikMenkad Indeed, this is non-trivial.

  • @TarikMenkad Tes, see the code on GitHub.

  • @GuusLöhlefink The OS should close it when the application quits. It might have to do with the status value.

  • That means you have to run it with arguments on the command line. So run it as, e.g.,
    ./formatted_write.exe 10 bla.txt

  • @JulioMendez It will still depend on what is the default floating point kind the compiler uses. This is implementation specific, so it would still be safer to be explicit.

  • @JulioMendez In 'next steps' are several references to books on Fortran that I like (and use).

  • @JulioMendez You can write output to the screen via two streams, standard output and standard error (output_unit and error_unit). By default, they both appear on the screen while the application is executed.
    However, in a shell you can do I/O redirection, i.e., you can send one of these streams to a file, while the other still appears on the screen, e.g.,...

  • @TarikMenkad You're right, the N shouldn't be there, but rather the limit of the sum. Missing '^' in the LaTeX expression. Fixed now, thanks.

  • @TarikMenkad There are some errors in the animation, it is a good exercise to spot them ;)
    Frankly, it is not easy to redo since this was outsourced.

  • @JulioMendez It is important to have the _DP qualifier to ensure that no conversions have to be done. In this case, it is not required since I'm pretty sure the compiler will do the right thing, but when you have an actual computation that involves constants, conversions from single to double precision might have to be done under the hood. This will harm...

  • @GuusLöhlefink not even a simple print?

  • @TarikMenkad That is automatic. You can always assign a pointer to another pointer (of the same type).

  • You can use any editor you like, also a GUI editor.

  • @TarikMenkad I'd argue that it makes sense to have it anyway, since not every Fortran programmer is aware that initializing a variable in its declaration in a procedure makes it static.

  • @GuusLöhlefink Actually, mathematical function can return mulitple values. The return values can be tuples where each element is a member of a set, so that is well-defined.

  • Indeed, thanks, I fixed it.

  • @TarikMenkad Indeed, they were introduced to reduce build times among other things, we'll encounter them later.

  • Indeed, it is. since variables may leak into a compilation unit from its host, this can serve as an extra check.

  • @XingranWang Indeed.

  • @GuusLöhlefink real would be problematic since that is a Fortran keyword. INT32 could be used as a variable as long as you don't intend to use the one defined in iso_fortran_env.
    We'll discuss modules and the semantics of use and only later on.

  • @GuusLöhlefink Integers come in various sizes, i.e., numbers of bits to represent them. Fortran supports 8, 16, 32 and 64 bit integers. You can specify which kind you want using the kind argument in a declaration. Under the hood, kinds are represented as numbers, but that is not portable. Hence these kinds are defined as constants in iso_fortran_env. We...

  • @GuusLöhlefink I've always been a fan of ternary logic: true/false/maybe ;)

  • @SteveParfitt What you normally do for OpenMP where threads need to have a unique seed: in master, generate as many random numbers as threads, store them in an array of the appropriate length. In the parallel region, each thread seeds its random number generator with a value out of that array.
    However, you would also have to make sure the random number...

  • @TarikMenkad Indeed, you will find that implementation in the article on best practices.

  • @GuusLöhlefink The number you get depends on the system's state.

  • @SteveParfitt Excellent point. If you have access to Intel's OneAPI, the random number generators in MKL (Math Kernel Library) are quite good, and there are implementations of various algorithms.

  • @TarikMenkad Sorry, but no. Replacing the value attribute in the declaration of x and y by intent(in) will give you compilation errors. For arguments declared as intent(in) you can not have assignments.

    The variables x and y are not used in the code, so they shouldn't be declared here. I'll remove the declaration.

  • @TarikMenkad You're right, terminology slipped. It is assumed-length.

  • @SteveParfitt Avoiding conditional statements in loops altogether (if possible at all) may help. Branch prediction has improved, but it the CPU gets it wrong, things get inefficient.

  • @AntonLytvynenko There is an effort to develop a Fortran standard library. This would be rather nice, but it will be a while before it materializes as a standard.

  • @GuusLöhlefink Frankly, for me Fortran on Android makes not much sense, so I've never experimented with it. I'd recommend to use either a Linux environment, or a Wnidows IDE such as Eclipse or Code Blocks.

  • @VikasSharma You may find that there is more to Fortran than meets the eye. Of course, you can get a lot done with a subset of Fortran, but it is perhaps not as small a language as you might think.

  • @ChristianStocker Indeed, for C bindings, it is required, see week 5.

  • @AntonLytvynenko With pure subroutines yes, pure functions, no.

  • @AntonLytvynenko Indeed, you are correct, the right answer is 4.

  • @AntonLytvynenko The narrative is correct, the animation isn't. The assignment to list%first shouldn't be there, it should be list%last%next => element, followed by list%last => element.

  • @AntonLytvynenko The really, really clean way is to first use get_command_argument to retrieve the length of the argument, then allocate a buffer of that size, and subsequently use get_command_argument again to fill the buffer. See:...

  • @AntonLytvynenko Both are. If you do an allocate without the optional stat argument, the runtime will throw a runtime error. However, if you call it with the stat argument, it will fail silently, so it is up to you to check the value of the variable you passed as stat. If you don't do that, nobody knows that something went wrong, and you'll end up with a...

  • @AntonLytvynenko Both gfortran and ifort (Intel) support compiling with array bound checks at runtime. Of course, this comes at the cost of performance, so it is good to activate it while developing/debugging, but you'd have to switch that off for production.

  • @AntonLytvynenko Of course there are better profilers out there, but gprof is free and easy to use.

  • @ChristianStocker The value attribute explicitly states that this is call by value, rather than call by reference. Since we just want to pass a single real value with intent in, that is perfectly fine. There is no real advantage here, but it makes the intention very explicit.

  • @ChristianStocker You can move an allocation, and that allows you to "enlarge" an array dynamically, see

  • @AntonLytvynenko I'd say it's standard.

  • @AntonLytvynenko Unless you add the element to the beginning of the list, rather than to the end.

  • @NorwidBehrnd Please focus on the semantics of user defined types, rather than the very arbitrary example. These code fragments are taken from an application that has the sole purpose of illustrating how you can represent configuration data in Fortran using user defined types, and how you can parse a configuration file to populate a variable of this type.

  • @NorwidBehrnd It would be most relevant for procedures since they will take up most of the space. Compilation is done on a per-file basis, so the object file for the file that contains the module will have the implementations of all the procedures anyway. So that means it will depend on whether you are statically or dynamically linking your application. In...

  • @NorwidBehrnd No error. In the first place, it is not really relevant what "precision" represents, this section introduces user defined types. Secondly, It is intended to represent either an absolute or a relative convergence criterion, and that is a floating point value.

  • @GaryKlimowicz Thanks, glad you enjoyed it.

  • @GaryKlimowicz The OpenMP and MPI course typically address both C/C++ and Fortran programmers in one and the same training. It is not ideal, but there's the advantage that Fortran programmers get exposed ot a bit of C and vice versa, and that not a bad thing.
    PRACE has a number of trainings that are relevant to Fortran programmers besides OpenMP and MPI. ...

  • @GaryKlimowicz Indeed, support is not particularly great. Intel partly supports coarrays, for GNU, you'd have to rely on a third-party library.

  • In scientific programming, you'd use OpenMP in C just as for Fortran. All major C/C++ compilers support t.

  • @PabloJavierSantamaría It's a nice alternative, but it is just buffers in disguise :)

  • @AntonLytvynenko The Fortran runtime does some bookkeeping, so in many circumstances, deallocation can be automatic. Not always though, which is why I prefer to explicitly deallocate.

  • @GaryKlimowicz Some interesting work is being done by John Gustafson (of HPC fame) on posits:

  • @GaryKlimowicz Indeed. Just to make sure, I experimented with GDB's & operator.