Open MPI logo

Open MPI Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Development mailing list

Subject: Re: [OMPI devel] Some questions about checkpoint/restart (9)
From: Takayuki Seki (seki_at_[hidden])
Date: 2010-04-02 04:59:27


> 1) t_mpi_question-9-packunpack.c

I did not put the program in 9th mail.

The program is as follows:

-bash-3.2$ cat t_mpi_question-9-packunpack.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "mpi.h"

#define SLPTIME 60

#define WORKBUFSIZ 64

struct dd {
   int x;
   int a;
   int y;
   int b;
   int c;
};

int main(int ac,char **av)
{
   int rank,size,cc,j,i;
   MPI_Request req;
   MPI_Status sts;
   struct dd buf,ans_dd_buf;
   char workbuf[WORKBUFSIZ];

   MPI_Init(&ac,&av);

   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
   MPI_Comm_size(MPI_COMM_WORLD,&size);

   if (rank == 0) {
     buf.x = 1;
     buf.a = 4329;
     buf.y = 2;
     buf.b = 8474;
     buf.c = 48;
   }
   else {
     buf.x = 0;
     buf.a = 0;
     buf.y = 0;
     buf.b = 0;
     buf.c = 0;
   }
   ans_dd_buf.x = 1;
   ans_dd_buf.a = 4329;
   ans_dd_buf.y = 2;
   ans_dd_buf.b = 8474;
   ans_dd_buf.c = 48;

   j=0; /* position */
   memset((void *)&workbuf[0],0,WORKBUFSIZ);

   if (rank == 0) {
     cc=MPI_Pack(&buf.x,1,MPI_INT,&workbuf[0],WORKBUFSIZ,&j,MPI_COMM_WORLD);
     if (cc != MPI_SUCCESS) { MPI_Abort(MPI_COMM_WORLD,-1); }
     cc=MPI_Pack(&buf.a,1,MPI_INT,&workbuf[0],WORKBUFSIZ,&j,MPI_COMM_WORLD);
     if (cc != MPI_SUCCESS) { MPI_Abort(MPI_COMM_WORLD,-1); }
     cc=MPI_Pack(&buf.y,1,MPI_INT,&workbuf[0],WORKBUFSIZ,&j,MPI_COMM_WORLD);
     if (cc != MPI_SUCCESS) { MPI_Abort(MPI_COMM_WORLD,-1); }
     cc=MPI_Pack(&buf.b,1,MPI_INT,&workbuf[0],WORKBUFSIZ,&j,MPI_COMM_WORLD);
     if (cc != MPI_SUCCESS) { MPI_Abort(MPI_COMM_WORLD,-1); }
     cc=MPI_Pack(&buf.c,1,MPI_INT,&workbuf[0],WORKBUFSIZ,&j,MPI_COMM_WORLD);
     if (cc != MPI_SUCCESS) { MPI_Abort(MPI_COMM_WORLD,-1); }
     MPI_Barrier(MPI_COMM_WORLD);
     MPI_Isend(&workbuf[0],j,MPI_PACKED,1,1000,MPI_COMM_WORLD,&req);
     printf(" rank=%d sleep start \n",rank); fflush(stdout);
     sleep(SLPTIME);
     printf(" rank=%d sleep end \n",rank); fflush(stdout);
     MPI_Wait(&req,&sts);
   }
   else {
     MPI_Barrier(MPI_COMM_WORLD);
     printf(" rank=%d sleep start \n",rank); fflush(stdout);
     sleep(SLPTIME);
     printf(" rank=%d sleep end \n",rank); fflush(stdout);
     MPI_Irecv(&workbuf[0],WORKBUFSIZ,MPI_PACKED,0,1000,MPI_COMM_WORLD,&req);
     MPI_Wait(&req,&sts);
     cc=MPI_Unpack(&workbuf[0],WORKBUFSIZ,&j,&buf.x,1,MPI_INT,MPI_COMM_WORLD);
     if (cc != MPI_SUCCESS) { MPI_Abort(MPI_COMM_WORLD,-1); }
     cc=MPI_Unpack(&workbuf[0],WORKBUFSIZ,&j,&buf.a,1,MPI_INT,MPI_COMM_WORLD);
     if (cc != MPI_SUCCESS) { MPI_Abort(MPI_COMM_WORLD,-1); }
     cc=MPI_Unpack(&workbuf[0],WORKBUFSIZ,&j,&buf.y,1,MPI_INT,MPI_COMM_WORLD);
     if (cc != MPI_SUCCESS) { MPI_Abort(MPI_COMM_WORLD,-1); }
     cc=MPI_Unpack(&workbuf[0],WORKBUFSIZ,&j,&buf.b,1,MPI_INT,MPI_COMM_WORLD);
     if (cc != MPI_SUCCESS) { MPI_Abort(MPI_COMM_WORLD,-1); }
     cc=MPI_Unpack(&workbuf[0],WORKBUFSIZ,&j,&buf.c,1,MPI_INT,MPI_COMM_WORLD);
     if (cc != MPI_SUCCESS) { MPI_Abort(MPI_COMM_WORLD,-1); }
   }

   printf(" rank=%d pass-3 %d %d %d %d %d \n"
     ,rank,buf.x,buf.a,buf.y,buf.b,buf.c); fflush(stdout);
   if (ans_dd_buf.x != buf.x) { MPI_Abort(MPI_COMM_WORLD,1); }
   if (ans_dd_buf.a != buf.a) { MPI_Abort(MPI_COMM_WORLD,1); }
   if (ans_dd_buf.y != buf.y) { MPI_Abort(MPI_COMM_WORLD,1); }
   if (ans_dd_buf.b != buf.b) { MPI_Abort(MPI_COMM_WORLD,1); }
   if (ans_dd_buf.c != buf.c) { MPI_Abort(MPI_COMM_WORLD,1); }

   MPI_Finalize();
   if (rank ==0) {
     printf(" rank=%d program end \n",rank); fflush(stdout);
   }
   return(0);
}