xref: /phasta/M2N/src/setsyncioparam.cc (revision 595995161822a203c8467e0e4a253d7bd7d6df32)
1 #include <fstream>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <vector>
5 #include <string.h>
6 #include <cstring>
7 #include <sys/types.h>
8 #include <dirent.h> // For opendir(),readdir(),...
9 #include <mpi.h>
10 #include "phastaIO.h"
11 
12 //#include "../include/Input.h"
13 #include "commonM2N_c.h"
14 #include "setsyncioparamM2N.h"
15 
16 
17 using namespace std; //useful for ifstream. Other solution is std::ifstream
18 
19 // extern void queryphmpiio_(const char[], int*, int*);
20 // void queryphmpiio_(const char filename[],int *nfields, int *nppf)
21 
setIOparam()22 void setIOparam()
23 {
24   int count;
25   int countRed;
26   int nfields;
27   int nppf;
28   int stepno;
29   int part;
30   char fname[255];
31   DIR *d;
32   struct dirent *filename;
33 
34 
35 //Number of geombc files
36   if(workfc.myrank == 0){
37     if( (d = opendir(".")) != NULL) {
38       count=0;
39       countRed=0;
40       while(filename=readdir(d)) {
41         //printf("%s\n", filename->d_name);
42         if(strncmp(filename->d_name,"geombc-dat",10)==0) {
43           count=count+1;
44         }
45         if(strncmp(filename->d_name,"geombcRed-dat",13)==0) {
46           countRed=countRed+1;
47         }
48       }
49       closedir(d);
50 
51       // Sanity check
52       if (count == 0) {
53         printf("ERROR: Could not find any geombc-dat file in the directory\n");
54       }
55       if (countRed == 0) {
56         printf("WARNING: Could not find any geombcRed-dat file in the directory\n");
57         printf("Either you are reducing down to 1 part (geombcRed not needed) or links are missing\n");
58         printf("Number of output SyncIO files will be set to either 1 or to the number of input SyncIO files read by M2N accordingly\n");
59       }
60 
61     }
62     else {
63       printf("ERROR when counting geombc-dat\n");
64     }
65   }
66 
67   MPI_Bcast( &count, 1, MPI_INT, 0, MPI_COMM_WORLD );
68   MPI_Bcast( &countRed, 1, MPI_INT, 0, MPI_COMM_WORLD );
69   //printf("Here we gogo: %d %d\n",workfc.myrank,count);
70 
71   outpar.nsynciofiles = count;
72   outpar.nsynciofilesred = countRed;
73   if(workfc.myrank == 0) {
74     printf("Number of geombc-dat and restart-dat files to read: %d\n", count);
75     printf("Number of geombcRed-dat and restartRed-dat files to read: %d\n", countRed);
76   }
77 
78 }
79 
detectd2wallfiles(int * numd2wallfiles)80 void detectd2wallfiles(int* numd2wallfiles)
81 {
82   int count;
83   int nfields;
84   int nppf;
85   int stepno;
86   int part;
87   char fname[255];
88   DIR *d;
89   struct dirent *filename;
90 
91 //Number of d2wall files
92   if(workfc.myrank == 0){
93     if( (d = opendir(".")) != NULL) {
94       count=0;
95       while(filename=readdir(d)) {
96         //printf("%s\n", filename->d_name);
97         if(strncmp(filename->d_name,"d2wall",6)==0) {
98           count=count+1;
99         }
100       }
101       closedir(d);
102     }
103   }
104 
105   MPI_Bcast( &count, 1, MPI_INT, 0, MPI_COMM_WORLD );
106   //printf("Here we gogo: %d %d\n",workfc.myrank,count);
107 
108   *numd2wallfiles = count;
109   if(workfc.myrank == 0) {
110     printf("Number of d2wall files present in the proc_case directory: %d\n", count);
111   }
112 
113 }
114 
115 
116 // void countfieldstowriterestart() //See new_interface.c
117