Opened 6 years ago

Last modified 5 years ago

#1065 new enhancement

Pass CCTK_ARGUMENTS more efficiently in Fortran

Reported by: Erik Schnetter Owned by:
Priority: major Milestone:
Component: Cactus Version:
Keywords: Cc:


CCTK_ARGUMENTS is passed differently in C and in Fortran. In C, only a single pointer is passed, pointing to cctkGH. The cctk_... variables and pointers to grid functions are defined locally from cctkGH. This is efficient, because (a) only a single variable is passed, and (b) the compiler can eliminate unused definitions.

In Fortran, all the cctk_... variables and all grid functions are passed explicitly. This is expensive for the caller, because hundreds of arguments have to be set up and passed to the subroutine. The compiler cannot eliminate any unused variables.

I suggest to change the Fortran calling convention to be the same as the one for C. Since regular Fortran pointers differ significantly from C pointers, I suggest to use "Cray pointers" instead, which are very similar to C pointers. Cray pointers are an extension to the Fortran standard, and are supported by all Fortran compilers I know of.

I attach sample code that shows how to declare, define, and use this convention.

Attachments (3)

sub.f90 (1.1 KB) - added by Erik Schnetter 6 years ago.
main.c (994 bytes) - added by Erik Schnetter 6 years ago.
Makefile (717 bytes) - added by Erik Schnetter 6 years ago.

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by Erik Schnetter

Attachment: sub.f90 added

Changed 6 years ago by Erik Schnetter

Attachment: main.c added

Changed 6 years ago by Erik Schnetter

Attachment: Makefile added

comment:1 Changed 6 years ago by Roland Haas

I did some experiments with Cray pointers on my own and found that adding

CCTK_REAL, DIMENSION(cctk_lsh(1),cctk_lsh(2),cctk_lsh(3)) :: evolution_mask
CCTK_POINTER_TO_CONST :: evolution_mask_ptr
pointer (evolution_mask_ptr, evolution_mask)

to EinsteinEvolve/GRHydro/src/GRHydro_Con2Prim.F90/check_GRHydro_C2P_failed around line 2238 leads to an internal compiler error with intel ifort 11.1 20100414

COMPILING arrangements/Zelmani/GRHydro/src/GRHydro_Con2Prim.F90

: catastrophic error: **Internal compiler error: internal abort** Please report this error along with the circumstances in which it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
in file arrangements/Zelmani/GRHydro/src/GRHydro_Con2Prim.F90, line 2220, column 12

compilation aborted for configs/bns_all/build/GRHydro/GRHydro_Con2Prim.f90 (code 3)

Note that I do not actually access the pointer at all. The ICE goes away if I comment out the OpenMP pragmas further down in the routine or if instead of cctk_lsh(1...2) I hard-code the pointee dimensions (say to 1,2,3 which of course is wrong).

So unless a workaround is found or CCTK_ARGUMENTS somehow does not trigger this then using Cray pointers (while a good idea I think) is not possible right now.

comment:2 Changed 6 years ago by Roland Haas

Erik suggested trying cctk_ash[123] instead of cctk_lsh([123]) which is (a) the correct thing to do since we introduced allocated sizes (in cctk_ash) local shapes (cctk_lsh) and (b) actually does not crash the compiler. So this no longers blocks using Cray pointers.

comment:3 Changed 5 years ago by Frank Löffler

Component: OtherCactus

Modify Ticket

Change Properties
Set your email in Preferences
as new The ticket will remain with no owner.
Next status will be 'review'.
as The resolution will be set.
to The owner will be changed from (none) to the specified user.
Next status will be 'confirmed'.
The owner will be changed from (none) to anonymous.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.