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