3.2 Readonly Global Variables

You can also use a pup routine to set up initial values for global variables on all processors. This pup routine is called with only a pup handle, just after the serial setup routine, and just before any parallel context routines start. The pup routine is never called with a deleting pup handle, so you need not handle that case.

A C example is:

     int g_arr[17];
     double g_f;
     int g_n; /*Length of array below*/
     float *g_allocated; /*heap-allocated array*/
 
     void pup_my_globals(pup_er p)
     {
       pup_ints(p,g_arr,17);
       pup_double(p,&g_f);
       pup_int(p,&g_n);
       if (pup_isUnpacking(p)) { /*Arriving on new processor*/
         g_allocated=malloc(g_n*sizeof(float));
       }
       pup_floats(p,g_allocated,g_n);
     }

A fortran example is:

     MODULE my_globals_mod
       INTEGER :: g_arr(17)
       DOUBLE PRECISION :: g_f
       INTEGER :: g_n
       SINGLE PRECISION, ALLOCATABLE :: g_allocated(:)
     END MODULE
 
     SUBROUTINE pup_my_globals(p)
       IMPLICIT NONE
       USE my_globals_mod
       USE pupmod
       INTEGER :: p
       call fpup_ints(p,g_arr,17)
       call fpup_double(p,g_f)
       call fpup_int(p,g_n)
       IF (fpup_isUnpacking(p)) THEN
         ALLOCATE(g_allocated(g_n))
       END IF
       call fpup_floats(p,g_allocated,g_n)
     END SUBROUTINE

You register your global variable pup routine using the method below. Multiple pup routines can be registered the same way.



void TCHARM_Readonly_globals(TCharmPupGlobalFn pup_fn)
SUBROUTINE TCHARM_Readonly_globals(pup_fn)
SUBROUTINE :: pup_fn

November 23, 2009
Charm Homepage