next up previous
Next: When to checkpoint Up: No Title Previous: Levels of Checkpointing

User level Checkpointing

Fortran77
Place all of the relevant variables that need to be checkpointed in a COMMON block. EQUIVALENCE that COMMON block to a large array, and place the lot in an include file that is included into every relevant subroutine:
       REAL*8 a,b,x(N),Y(N),Z(N),model(10*N)
       COMMON /modelcom/ a,b,x,y,z
       EQUIVALENCE a,model
The checkpoint routine simply writes model to a file, and the restart routine reads it (as a binary not text file):
SUBROUTINE checkpoint    SUBROUTINE restart
INCLUDE 'model.inc'      INCLUDE 'model.inc'
WRITE (8) model          READ (8) model
END                      END

C
Place all relevant variables to be checkpointed in a struct:
struct { double a,b,x[N],y[N],z[N]; } model;
Then the checkpoint/restart routines are:
FILE *checkpoint;
void checkpoint() {fwrite(&model,sizeof(model),1,checkpoint);}
void restart() {fread(&model,sizeof(model),1,checkpoint);}
NB: pointers cause problems! It may also be desirable to define macros for the model variables as a convenience factor:
#define a model.a
Fortran90
Can also use the C technique employing the compound type definition feature. (TYPE) However, pointers and allocatable arrays are problematic.

C++
Proceed as for C, only now the model's calculation can be made a method of the struct, which avoids the need for macro definitions:
struct { 
  double a,b,x[N],y[N],z[N]; 
  compute();
} model;
By using the object descriptor technology used in Eco Lab4
(http://parallel.hpc.unsw.edu.au/rks/ecolab), pointers and dynamic types can be handled, and the checkpoint file may optionally be written in a machine independent XDR format.


next up previous
Next: When to checkpoint Up: No Title Previous: Levels of Checkpointing
Russell Standish
2001-05-04