Enable optimisation in Fortran array index calculations

Create issue
Issue #544 closed
Erik Schnetter created an issue

In Fortran, Cactus passes all grid functions as arguments to routines, and the size of the grid functions are declared in DECLARE_CCTK_ARGUMENTS. In these declarations, Cactus assumes that the size of each grid variable group can be different, and the compiler thus does not see that all grid functions have (locally) the same array shape. The compiler can thus not simplify array index calculations. This is probably only relevant in short loops accessing grid functions from multiple groups (GRHydro?).

The attached patch passes three additional integer arguments (cctk_lsh[123]) which contain the shape of grid functions, and uses these to declare grid functions.

This patch is quite old, but was never applied. It comes from a time when g77 didn't support declaring array shapes via an integer array (since this is not allowed in Fortran 77). If this is now possible, one could use the array cctk_lsh instead of passing three extra integer arguments.


Comments (8)

  1. Frank Löffler
    • removed comment

    If I understood correctly, this patch would change the declaration not only for Fortran 90, but also for Fortran 77 code. Wouldn't that break Fortran 77 code when a compiler follows the standard strictly?

  2. Erik Schnetter reporter
    • removed comment

    No, this patch uses a mechanism that follows the Fortran 77 standard, apart from the usual ways in which one violates this standard anyway (using implicit none, line lengths, number of continuation lines, etc.)

    Apart from this: I would be very surprised if we found a true Fortran 77 compiler these days that isn't just a Fortran 90 compiler (Fortran is backward compatible, apart from really murky corners that we don't touch anyway). In fact, we could probably remove support for Fortran 77 from Cactus without anybody noticing. (By default, Cactus overwrites all Fortran 77 settings with Fortran 90 settings, since this ensures that the Fortran 77 and Fortran 90 compilers are compatible -- if one uses the Fortran 90 compiler to build Fortran 77 code, this will be ensured...)

  3. Ian Hinder
    • removed comment

    I'm not really familiar with either Fortran or the flesh files that this patch touches. Frank, should the patch be committed?

  4. Frank Löffler
    • changed status to open
    • assigned issue to
    • removed comment
    • changed watchers to peterdiener

    I looked over the patch, and it seems to be ok, but didn't test it. However, Fortran and me are usually not getting along well, so I will ask Peter to provide input.

  5. Peter Diener
    • removed comment

    I applied the patch and used it to compile WaveToyF77 and WaveToyFree90. As far as I can see the patch is not complete. It does pass in cctk_lsh1, cctk_lsh2 and cctk_lsh3, but these are not used when declaring the grid functions later on. The grid functions are still declared the same was as before applying the patch, with distinct integers for each grid function.

  6. Log in to comment