tutorial/12.buddycr.c
/* mockup checkpoint restart: we reset iteration, and we prevent further
 * error injection */
mockup checkpoint restart: we reset iteration, and we prevent further
error injection
mockup checkpoint restart : we reset iteration and we prevent further error injection
static int app_reload_ckpt(MPI_Comm comm) {
    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &np);
    MPI_Sendrecv(&ckpt_iteration, 1, MPI_INT, rbuddy(rank), ckpt_tag,
                 &iteration, 1, MPI_INT, lbuddy(rank), ckpt_tag,
                 comm, MPI_STATUS_IGNORE);
    if( -1 == iteration && -1 == ckpt_iteration ) {
        fprintf(stderr, "Rank %04d: Buddy checkpointing cannot restart from these failures because my buddy %04d wants the checkpoint I have lost...\n", rank, lbuddy(rank));
        MPI_Abort(comm, -1);
    }
    if( -1 == iteration ) {
        if(verbose) fprintf(stderr, "Rank %04d: sending checkpoint to %04d at iteration %d\n", rank, lbuddy(rank), ckpt_iteration);
        MPI_Send(buddy_ckpt, count, MPI_DOUBLE, lbuddy(rank), ckpt_tag, comm);
    }
    if( -1 == ckpt_iteration ) {
        if(verbose) fprintf(stderr, "Rank %04d: restarting from %04d at iteration %d\n", rank, rbuddy(rank), iteration);
        MPI_Recv(mydata_array, count, MPI_DOUBLE, rbuddy(rank), ckpt_tag, comm, MPI_STATUS_IGNORE);
    }
    else {
        MPI_Sendrecv(my_ckpt, count, MPI_DOUBLE, 0, ckpt_tag,
                     mydata_array, count, MPI_DOUBLE, 0, ckpt_tag,
                     MPI_COMM_SELF, MPI_STATUS_IGNORE);
        iteration = ckpt_iteration;
    }
    return 0;
}
static int app_reload_ckpt ( MPI_Comm comm ) { MPI_Comm_rank ( comm , & rank ) ; MPI_Comm_size ( comm , & np ) ; MPI_Sendrecv ( & ckpt_iteration , 1 , MPI_INT , rbuddy ( rank ) , ckpt_tag , & iteration , 1 , MPI_INT , lbuddy ( rank ) , ckpt_tag , comm , MPI_STATUS_IGNORE ) ; if ( -1 == iteration && -1 == ckpt_iteration ) { fprintf ( stderr , " \n " , rank , lbuddy ( rank ) ) ; MPI_Abort ( comm , -1 ) ; } if ( -1 == iteration ) { if ( verbose ) fprintf ( stderr , " \n " , rank , lbuddy ( rank ) , ckpt_iteration ) ; MPI_Send ( buddy_ckpt , count , MPI_DOUBLE , lbuddy ( rank ) , ckpt_tag , comm ) ; } if ( -1 == ckpt_iteration ) { if ( verbose ) fprintf ( stderr , " \n " , rank , rbuddy ( rank ) , iteration ) ; MPI_Recv ( mydata_array , count , MPI_DOUBLE , rbuddy ( rank ) , ckpt_tag , comm , MPI_STATUS_IGNORE ) ; } else { MPI_Sendrecv ( my_ckpt , count , MPI_DOUBLE , 0 , ckpt_tag , mydata_array , count , MPI_DOUBLE , 0 , ckpt_tag , MPI_COMM_SELF , MPI_STATUS_IGNORE ) ; iteration = ckpt_iteration ; } return 0 ; }
mockup checkpoint restart: we reset iteration, and we prevent further
 error injection
mockup checkpoint restart : we reset iteration and we prevent further error injection
/* send my ckpt_iteration to my buddy to decide if we need to exchange a
     * checkpoint
     *   If ckpt_iteration is -1, I am restarting.
     *   It iteration is -1, then my buddy is restarting.
     *   Note: if an error occurs now, it will be absorbed by the error handler
     *   and the restart will be repeated.
     */ /* My buddy was dead, send the checkpoint */ /* I replace a dead, get the ckeckpoint */ /* iteration has already been set by the sendrecv above */ /* I am a survivor,
         * Memcopy my own checkpoint back in my memory */ /* Reset iteration */