xref: /phasta/phSolver/common/test/phIOreaddatablock.cc (revision fe88b52d35537d3736cc3d33d9db7e51353aba7d)
1 #include <mpi.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include "phIO.h"
6 
7 int main(int argc, char* argv[]) {
8   MPI_Init(&argc,&argv);
9   int rank;
10   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
11   if( argc != 2 ) {
12     fprintf(stderr, "Usage: %s <numSyncFiles>\n",argv[0]);
13     MPI_Finalize();
14     return 1;
15   }
16   int nfiles[2] = {atoi(argv[1]), 1};
17   const char* phrase = "co-ordinates";
18   const char* type = "double";
19   const char* iotype = "binary";
20   const char* dir[2] = {"4-procs_case-SyncIO-2", "4-procs_case-Posix"};
21   const char* filename[2] = {"geombc-dat.", "geombc.dat."};
22   double* coords[2] = {NULL, NULL};
23   int len[2] = {0, 0};
24   int numpts[2];
25   phio_fp file;
26   int two = 2;
27   for(int i=0; i<2; i++) {
28     chdir(dir[i]);
29     MPI_Barrier(MPI_COMM_WORLD);
30     phio_openfile_read(filename[i], &(nfiles[i]), &file);
31     phio_readheader(file, phrase, numpts, &two, type, iotype);
32     len[i] = numpts[0]*3; //numPts * 3 dimensions
33     fprintf(stderr, "%d %s len %d\n", rank, __func__, len[i]);
34     coords[i] = (double*) malloc(len[i]*sizeof(double));
35     phio_readdatablock(file, phrase, coords[i], &(len[i]), type, iotype);
36     phio_closefile_read(file);
37     chdir("..");
38     MPI_Barrier(MPI_COMM_WORLD);
39     if(!rank)
40       fprintf(stderr, "-------------------\n");
41   }
42   int match = (len[0] == len[1]);
43   if(!rank && match)
44     fprintf(stderr, "number of points match!\n");
45   if(!rank && !match) {
46     fprintf(stderr, "number of points don't match... :(\n");
47     return 1;
48   }
49 
50   match = true;
51   for(int i=0; i<len[0]; i++)
52     match = match && ( coords[0][i] == coords[1][i] );
53 
54   if(!rank && match)
55     fprintf(stderr, "points match!\n");
56   if(!rank && !match) {
57     fprintf(stderr, "points don't match... :(\n");
58     return 1;
59   }
60 
61   for(int i=0; i<2; i++)
62     free(coords[i]);
63 
64   MPI_Finalize();
65   return !match;
66 }
67