have DECLARE_CCTK_ARGUMENTS_CHECKED hide cctkGH members that do not exist in LEVEL mode etc.

Issue #2418 new
Roland Haas created an issue

Certain cctkGH members (eg nghostzones) do not contain useful values in all modes, eg not in LEVEL mode. This causes problems every once in a while, eg: #2288.

Using the CHECKED macros we can actually avoid defining C / Fortran variables for those members when a scheduled functions is scheduled only in a given mode and turn a runtime error into a compile time error.

Comments (6)

  1. Roland Haas reporter

    oh no. this is an enhancement request, not a review request. Ie a note that this might be good to have and suggestion that anyone who feel inclined to implement this could find themselves with an appreciative audience.

  2. Steven R. Brandt

    @Roland Haas how do you envision this working? Does it read the mode from schedule.ccl and generate accordingly?

  3. Roland Haas reporter

    yes, that was my idea. Since the presync code in rdwr.pl already reads and parses schedule.ccl and controls what goes into DECLARE_CCTK_ARGUMENTS_FunctionName it could also do that. Namely I am only thinking about the plain cctk_nghostzones variable (as an example) that DECLARE_CCTK_ARGUMENTS provides and not the actual member of the structure pointed to be cctkGH.

  4. Erik Schnetter

    This macro could have a different name, e.g. having “level” or “global” in its name. I don’t know whether this is a good idea. Of course, grid functions should not be declared in level or global mode.

    -erik

  5. Roland Haas reporter

    There may be some issues to consider. Eg one use of “options: GLOBAL” is if the scheduled function does its own looping over components etc. Something like (I cannot remember the exact syntax of the various mode changing macros):

    schedule MyThorn_Func
    {
      options: global
    
      READS: mygf
    
      lang: C
    } "do something with the data on the grid"
    

    and then

    void MyTHorn_Func(CCTK_ARGUMENTS)
    {
      BEGIN_REFLEVEL_LOOP(cctkGH) {
        BEGIN_LOCAL_MAP_LOOP{(cctkGH, reflevel)}
          BEGIN_LOCAL_COMPONENT_LOOP(cctkGH, map) {
            DECLARE_CCTK_ARGUTMENTS_MyThorn_Fun;
            for(int i = 0 ; i < cctk_lsh[0] ; i++) {
              int idx = CCTK_GFINDEX3D(cctkGH, i,0,0);
              double value = mygf[idx];
            }
          } END_LOCAL_COMPONENT_LOOP;
        } END_LOCAL_MAP_LOOP
      } END_REFLEVEL_LOOP;
    

    which is perfectly valid code and ends up using the cctkGH members cctk_lsh etc. that are not normally valid for a globally scheduled function since the function itself enters local mode.

  6. Log in to comment