xref: /phasta/phSolver/common/test/phIOreaddatablock.cc (revision 6d0848bbfae688860d74cb6434f989d07b1aad31)
14a32e26dSCameron Smith #include <mpi.h>
24a32e26dSCameron Smith #include <stdio.h>
34a32e26dSCameron Smith #include <stdlib.h>
44a32e26dSCameron Smith #include <unistd.h>
54a32e26dSCameron Smith #include "phIO.h"
6ab645d52SCameron Smith #include "syncio.h"
7ab645d52SCameron Smith #include "posixio.h"
84a32e26dSCameron Smith 
main(int argc,char * argv[])94a32e26dSCameron Smith int main(int argc, char* argv[]) {
104a32e26dSCameron Smith   MPI_Init(&argc,&argv);
114a32e26dSCameron Smith   int rank;
124a32e26dSCameron Smith   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
134a32e26dSCameron Smith   if( argc != 2 ) {
144a32e26dSCameron Smith     fprintf(stderr, "Usage: %s <numSyncFiles>\n",argv[0]);
154a32e26dSCameron Smith     MPI_Finalize();
164a32e26dSCameron Smith     return 1;
174a32e26dSCameron Smith   }
18ab645d52SCameron Smith   int nfiles = atoi(argv[1]);
194a32e26dSCameron Smith   const char* phrase = "co-ordinates";
204a32e26dSCameron Smith   const char* type = "double";
214a32e26dSCameron Smith   const char* iotype = "binary";
22*50eda766SCameron Smith   const char* dir[2] = {"4-procs_case-SyncIO-2_ref", "4-procs_case-Posix_ref"};
234a32e26dSCameron Smith   const char* filename[2] = {"geombc-dat.", "geombc.dat."};
244a32e26dSCameron Smith   double* coords[2] = {NULL, NULL};
254a32e26dSCameron Smith   int len[2] = {0, 0};
264a32e26dSCameron Smith   int numpts[2];
27ab645d52SCameron Smith   phio_fp file[2];
28ab645d52SCameron Smith   syncio_setup_read(nfiles, &(file[0]));
29ab645d52SCameron Smith   posixio_setup(&(file[1]), 'r');
304a32e26dSCameron Smith   int two = 2;
314a32e26dSCameron Smith   for(int i=0; i<2; i++) {
324a32e26dSCameron Smith     chdir(dir[i]);
334a32e26dSCameron Smith     MPI_Barrier(MPI_COMM_WORLD);
34ab645d52SCameron Smith     phio_openfile(filename[i], file[i]);
35ab645d52SCameron Smith     phio_readheader(file[i], phrase, numpts, &two, type, iotype);
364a32e26dSCameron Smith     len[i] = numpts[0]*3; //numPts * 3 dimensions
374a32e26dSCameron Smith     fprintf(stderr, "%d %s len %d\n", rank, __func__, len[i]);
384a32e26dSCameron Smith     coords[i] = (double*) malloc(len[i]*sizeof(double));
39ab645d52SCameron Smith     phio_readdatablock(file[i], phrase, coords[i], &(len[i]), type, iotype);
40ab645d52SCameron Smith     phio_closefile(file[i]);
414a32e26dSCameron Smith     chdir("..");
424a32e26dSCameron Smith     MPI_Barrier(MPI_COMM_WORLD);
434a32e26dSCameron Smith     if(!rank)
444a32e26dSCameron Smith       fprintf(stderr, "-------------------\n");
454a32e26dSCameron Smith   }
464a32e26dSCameron Smith   int match = (len[0] == len[1]);
474a32e26dSCameron Smith   if(!rank && match)
484a32e26dSCameron Smith     fprintf(stderr, "number of points match!\n");
494a32e26dSCameron Smith   if(!rank && !match) {
504a32e26dSCameron Smith     fprintf(stderr, "number of points don't match... :(\n");
514a32e26dSCameron Smith     return 1;
524a32e26dSCameron Smith   }
534a32e26dSCameron Smith 
544a32e26dSCameron Smith   match = true;
554a32e26dSCameron Smith   for(int i=0; i<len[0]; i++)
564a32e26dSCameron Smith     match = match && ( coords[0][i] == coords[1][i] );
574a32e26dSCameron Smith 
584a32e26dSCameron Smith   if(!rank && match)
594a32e26dSCameron Smith     fprintf(stderr, "points match!\n");
604a32e26dSCameron Smith   if(!rank && !match) {
614a32e26dSCameron Smith     fprintf(stderr, "points don't match... :(\n");
624a32e26dSCameron Smith     return 1;
634a32e26dSCameron Smith   }
644a32e26dSCameron Smith 
654a32e26dSCameron Smith   for(int i=0; i<2; i++)
664a32e26dSCameron Smith     free(coords[i]);
674a32e26dSCameron Smith 
684a32e26dSCameron Smith   MPI_Finalize();
694a32e26dSCameron Smith   return !match;
704a32e26dSCameron Smith }
71