1 #define OMPI_SKIP_MPICXX 1 2 #include <mpi.h> 3 #include <stdio.h> 4 #include <stdlib.h> 5 #include <string.h> 6 7 #include <sys/types.h> 8 #include <sys/stat.h> 9 10 #include "common_c.h" 11 12 #include "phstream.h" 13 #include "streamio.h" 14 15 #if !(defined IOSTREAMH) 16 #include <iostream> 17 #include <sstream> 18 using namespace std; 19 #endif 20 21 #include <FCMangle.h> 22 #define input FortranCInterface_GLOBAL_(input,INPUT) 23 #define proces FortranCInterface_GLOBAL_(proces,PROCES) 24 #define timer FortranCInterface_GLOBAL_(timer,TIMER) 25 26 #ifdef intel 27 #include <direct.h> 28 #define chdir _chdir 29 #else 30 #include <unistd.h> 31 #endif 32 33 extern "C" char phasta_iotype[80]; 34 char phasta_iotype[80]; 35 36 extern int SONFATH; 37 extern "C" void proces(); 38 extern "C" void input(); 39 extern int input_fform(char inpfname[]); 40 extern void setIOparam(); // For SyncIO 41 42 int myrank; /* made file global for ease in debugging */ 43 44 void 45 catchDebugger() { 46 while (1) { 47 int debuggerPresent=0; 48 int fakeSTOP = 1; // please stop HERE and assign as next line 49 // assign or set debuggerPresent=1 50 if(debuggerPresent) { 51 break; 52 } 53 } 54 } 55 56 // some useful debugging functions 57 58 void 59 pdarray( void* darray , int start, int end ) { 60 for( int i=start; i < end; i++ ){ 61 cout << ((double*)darray)[i] << endl; 62 } 63 } 64 65 void 66 piarray( void* iarray , int start, int end ) { 67 for( int i=start; i < end; i++ ){ 68 cout << ((int*)iarray)[i] << endl; 69 } 70 } 71 72 int phasta(int argc, 73 char *argv[], 74 grstream grs) { 75 int size,ierr; 76 char inpfilename[100]; 77 MPI_Comm_size (MPI_COMM_WORLD, &size); 78 MPI_Comm_rank (MPI_COMM_WORLD, &myrank); 79 80 workfc.numpe = size; 81 workfc.myrank = myrank; 82 outpar.input_mode = -1; //FIXME magic value for streams 83 outpar.output_mode = 1; //FIXME magic value for syncio 84 streamio_set_gr(grs); 85 86 /* Input data */ 87 ierr = input_fform("solver.inp"); 88 if(!ierr){ 89 sprintf(inpfilename,"%d-procs_case/",size); 90 if( chdir( inpfilename ) ) { 91 cerr << "could not change to the problem directory " 92 << inpfilename << endl; 93 return 1; 94 } 95 MPI_Barrier(MPI_COMM_WORLD); 96 input(); 97 /* now we can start the solver */ 98 proces(); 99 } 100 else{ 101 printf("error during reading ascii input \n"); 102 } 103 MPI_Barrier(MPI_COMM_WORLD); 104 if ( myrank == 0 ) { 105 printf("phasta.cc - last call before finalize!\n"); 106 } 107 return 0; 108 } 109 110 int phasta(int argc, 111 char *argv[], 112 RStream* rs) { 113 fprintf(stderr, "HEY! if you see this email Cameron and tell him " 114 "to implement %s(...) on line %d of %s " 115 "... returning an error\n", __func__, __LINE__, __FILE__); 116 return 1; 117 } 118 119 int phasta(int argc, 120 char *argv[], 121 GRStream* grs, 122 RStream* rs) { 123 int size,ierr; 124 char inpfilename[100]; 125 MPI_Comm_size (MPI_COMM_WORLD, &size); 126 MPI_Comm_rank (MPI_COMM_WORLD, &myrank); 127 128 workfc.numpe = size; 129 workfc.myrank = myrank; 130 outpar.input_mode = -1; //FIXME magic value for streams 131 outpar.output_mode = -1; //FIXME magic value for streams 132 streamio_set_gr(grs); 133 streamio_set_r(rs); 134 135 /* Input data */ 136 ierr = input_fform("solver.inp"); 137 if(!ierr){ 138 sprintf(inpfilename,"%d-procs_case/",size); 139 if( chdir( inpfilename ) ) { 140 cerr << "could not change to the problem directory " 141 << inpfilename << endl; 142 return 1; 143 } 144 MPI_Barrier(MPI_COMM_WORLD); 145 input(); 146 /* now we can start the solver */ 147 proces(); 148 } 149 else{ 150 printf("error during reading ascii input \n"); 151 } 152 MPI_Barrier(MPI_COMM_WORLD); 153 if ( myrank == 0 ) { 154 printf("phasta.cc - last call before finalize!\n"); 155 } 156 if( chdir("..") ) { 157 cerr << "could not change to the parent directory\n"; 158 return 1; 159 } 160 } 161 162 int phasta( int argc, 163 char *argv[] ) { 164 int size,ierr; 165 char inpfilename[100]; 166 char* pauseDebugger = getenv("catchDebugger"); 167 MPI_Comm_size (MPI_COMM_WORLD, &size); 168 MPI_Comm_rank (MPI_COMM_WORLD, &myrank); 169 170 workfc.numpe = size; 171 workfc.myrank = myrank; 172 173 #if (defined WIN32) 174 if(argc > 2 ){ 175 catchDebugger(); 176 } 177 #endif 178 #if (1) // ALWAYS ( defined LAUNCH_GDB ) && !( defined WIN32 ) 179 180 if ( pauseDebugger ) { 181 182 int parent_pid = getpid(); 183 int gdb_child = fork(); 184 cout << "gdb_child" << gdb_child << endl; 185 186 if( gdb_child == 0 ) { 187 188 cout << "Debugger Process initiating" << endl; 189 stringstream exec_string; 190 191 #if ( defined decalp ) 192 exec_string <<"xterm -e idb " 193 << " -pid "<< parent_pid <<" "<< argv[0] << endl; 194 #endif 195 #if ( defined LINUX ) 196 exec_string <<"xterm -e gdb" 197 << " -pid "<< parent_pid <<" "<< argv[0] << endl; 198 #endif 199 #if ( defined SUN4 ) 200 exec_string <<"xterm -e dbx " 201 << " - "<< parent_pid <<" "<< argv[0] << endl; 202 #endif 203 #if ( defined IRIX ) 204 exec_string <<"xterm -e dbx " 205 << " -p "<< parent_pid <<" "<< argv[0] << endl; 206 #endif 207 string s = exec_string.str(); 208 system( s.c_str() ); 209 exit(0); 210 } 211 catchDebugger(); 212 } 213 214 #endif 215 216 /* Input data */ 217 if(argc > 1 ){ 218 strcpy(inpfilename,argv[1]); 219 } else { 220 strcpy(inpfilename,"solver.inp"); 221 } 222 ierr = input_fform(inpfilename); 223 if(!ierr){ 224 sprintf(inpfilename,"%d-procs_case/",size); 225 if( chdir( inpfilename ) ) { 226 cerr << "could not change to the problem directory " 227 << inpfilename << endl; 228 return 1; 229 } 230 MPI_Barrier(MPI_COMM_WORLD); 231 setIOparam(); 232 outpar.input_mode = outpar.nsynciofiles; //FIXME this is awful 233 outpar.output_mode = outpar.nsynciofiles; //FIXME this is awful 234 input(); 235 /* now we can start the solver */ 236 proces(); 237 } 238 else{ 239 printf("error during reading ascii input \n"); 240 } 241 MPI_Barrier(MPI_COMM_WORLD); 242 if ( myrank == 0 ) { 243 printf("phasta.cc - last call before finalize!\n"); 244 } 245 return 0; 246 } 247