19ec3dd51SCameron Smith #include <mpi.h>
29ec3dd51SCameron Smith #include <stdio.h>
39ec3dd51SCameron Smith #include <stdlib.h>
49ec3dd51SCameron Smith #include <unistd.h>
59ec3dd51SCameron Smith #include "phIO.h"
6*ab645d52SCameron Smith #include "syncio.h"
7*ab645d52SCameron Smith #include "posixio.h"
89ec3dd51SCameron Smith
main(int argc,char * argv[])99ec3dd51SCameron Smith int main(int argc, char* argv[]) {
109ec3dd51SCameron Smith MPI_Init(&argc,&argv);
119ec3dd51SCameron Smith int rank;
129ec3dd51SCameron Smith MPI_Comm_rank(MPI_COMM_WORLD, &rank);
139ec3dd51SCameron Smith int size;
149ec3dd51SCameron Smith MPI_Comm_size(MPI_COMM_WORLD, &size);
159ec3dd51SCameron Smith if( argc != 2 ) {
169ec3dd51SCameron Smith fprintf(stderr, "Usage: %s <numSyncFiles>\n",argv[0]);
179ec3dd51SCameron Smith MPI_Finalize();
189ec3dd51SCameron Smith return 1;
199ec3dd51SCameron Smith }
209ec3dd51SCameron Smith const char* phrase = "number of fishes";
219ec3dd51SCameron Smith const char* type = "double";
229ec3dd51SCameron Smith const char* iotype = "binary";
23*ab645d52SCameron Smith int one = 1;
249ec3dd51SCameron Smith int fish = 2;
259ec3dd51SCameron Smith int numFish[2] = {0,0};
269ec3dd51SCameron Smith double fishWeight[2] = {1.23,1.23};
27*ab645d52SCameron Smith int nfiles = atoi(argv[1]);
28*ab645d52SCameron Smith int ppf = size/nfiles;
299ec3dd51SCameron Smith const char* filename[2] = {"water-dat.", "water.dat."};
30*ab645d52SCameron Smith phio_fp file[2];
31*ab645d52SCameron Smith syncio_setup_write(nfiles, one, ppf, &(file[0]));
32*ab645d52SCameron Smith posixio_setup(&(file[1]), 'w');
339ec3dd51SCameron Smith for(int i=0; i<2; i++) {
34*ab645d52SCameron Smith phio_openfile(filename[i], file[i]);
35*ab645d52SCameron Smith phio_writeheader(file[i], phrase, &fish, &one, &one, type, iotype);
36*ab645d52SCameron Smith phio_writedatablock(file[i], phrase, &(fishWeight[i]), &one, type, iotype);
37*ab645d52SCameron Smith phio_closefile(file[i]);
389ec3dd51SCameron Smith }
39*ab645d52SCameron Smith syncio_setup_read(nfiles, &(file[0]));
40*ab645d52SCameron Smith posixio_setup(&(file[1]), 'r');
419ec3dd51SCameron Smith for(int i=0; i<2; i++) {
42*ab645d52SCameron Smith phio_openfile(filename[i], file[i]);
43*ab645d52SCameron Smith phio_readheader(file[i], phrase, &(numFish[i]), &one, type, iotype);
44*ab645d52SCameron Smith phio_readdatablock(file[i], phrase, &(fishWeight[i]), &one, type, iotype);
45*ab645d52SCameron Smith phio_closefile(file[i]);
469ec3dd51SCameron Smith }
479ec3dd51SCameron Smith int match = (numFish[0] == numFish[1]) && (fishWeight[0] == fishWeight[1]);
489ec3dd51SCameron Smith if(!rank && match)
499ec3dd51SCameron Smith fprintf(stderr, "number of fish match!\n");
509ec3dd51SCameron Smith if(!rank && !match)
519ec3dd51SCameron Smith fprintf(stderr, "number of fish don't match... :(\n");
529ec3dd51SCameron Smith MPI_Finalize();
539ec3dd51SCameron Smith return !match;
549ec3dd51SCameron Smith }
55