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(grstream grs) { 73 int size,ierr; 74 char inpfilename[100]; 75 MPI_Comm_size (MPI_COMM_WORLD, &size); 76 MPI_Comm_rank (MPI_COMM_WORLD, &myrank); 77 78 workfc.numpe = size; 79 workfc.myrank = myrank; 80 outpar.input_mode = -1; //FIXME magic value for streams 81 outpar.output_mode = 1; //FIXME magic value for syncio 82 streamio_set_gr(grs); 83 84 /* Input data */ 85 ierr = input_fform("solver.inp"); 86 if(!ierr){ 87 sprintf(inpfilename,"%d-procs_case/",size); 88 if( chdir( inpfilename ) ) { 89 cerr << "could not change to the problem directory " 90 << inpfilename << endl; 91 return 1; 92 } 93 MPI_Barrier(MPI_COMM_WORLD); 94 input(); 95 /* now we can start the solver */ 96 proces(); 97 } 98 else{ 99 printf("error during reading ascii input \n"); 100 } 101 MPI_Barrier(MPI_COMM_WORLD); 102 if ( myrank == 0 ) { 103 printf("phasta.cc - last call before finalize!\n"); 104 } 105 return 0; 106 } 107 108 int phasta(RStream* rs) { 109 fprintf(stderr, "HEY! if you see this email Cameron and tell him " 110 "to implement %s(...) on line %d of %s " 111 "... returning an error\n", __func__, __LINE__, __FILE__); 112 return 1; 113 } 114 115 int phasta(GRStream* grs, RStream* rs) { 116 int size,ierr; 117 char inpfilename[100]; 118 MPI_Comm_size (MPI_COMM_WORLD, &size); 119 MPI_Comm_rank (MPI_COMM_WORLD, &myrank); 120 121 workfc.numpe = size; 122 workfc.myrank = myrank; 123 outpar.input_mode = -1; //FIXME magic value for streams 124 outpar.output_mode = -1; //FIXME magic value for streams 125 streamio_set_gr(grs); 126 streamio_set_r(rs); 127 128 /* Input data */ 129 ierr = input_fform("solver.inp"); 130 if(!ierr){ 131 sprintf(inpfilename,"%d-procs_case/",size); 132 if( chdir( inpfilename ) ) { 133 cerr << "could not change to the problem directory " 134 << inpfilename << endl; 135 return 1; 136 } 137 MPI_Barrier(MPI_COMM_WORLD); 138 input(); 139 /* now we can start the solver */ 140 proces(); 141 } 142 else{ 143 printf("error during reading ascii input \n"); 144 } 145 MPI_Barrier(MPI_COMM_WORLD); 146 if ( myrank == 0 ) { 147 printf("phasta.cc - last call before finalize!\n"); 148 } 149 if( chdir("..") ) { 150 cerr << "could not change to the parent directory\n"; 151 return 1; 152 } 153 } 154 155 int phasta( int argc, char *argv[] ) { 156 int size,ierr; 157 char inpfilename[100]; 158 char* pauseDebugger = getenv("catchDebugger"); 159 MPI_Comm_size (MPI_COMM_WORLD, &size); 160 MPI_Comm_rank (MPI_COMM_WORLD, &myrank); 161 162 workfc.numpe = size; 163 workfc.myrank = myrank; 164 165 #if (defined WIN32) 166 if(argc > 2 ){ 167 catchDebugger(); 168 } 169 #endif 170 #if (1) // ALWAYS ( defined LAUNCH_GDB ) && !( defined WIN32 ) 171 172 if ( pauseDebugger ) { 173 174 int parent_pid = getpid(); 175 int gdb_child = fork(); 176 cout << "gdb_child" << gdb_child << endl; 177 178 if( gdb_child == 0 ) { 179 180 cout << "Debugger Process initiating" << endl; 181 stringstream exec_string; 182 183 #if ( defined decalp ) 184 exec_string <<"xterm -e idb " 185 << " -pid "<< parent_pid <<" "<< argv[0] << endl; 186 #endif 187 #if ( defined LINUX ) 188 exec_string <<"xterm -e gdb" 189 << " -pid "<< parent_pid <<" "<< argv[0] << endl; 190 #endif 191 #if ( defined SUN4 ) 192 exec_string <<"xterm -e dbx " 193 << " - "<< parent_pid <<" "<< argv[0] << endl; 194 #endif 195 #if ( defined IRIX ) 196 exec_string <<"xterm -e dbx " 197 << " -p "<< parent_pid <<" "<< argv[0] << endl; 198 #endif 199 string s = exec_string.str(); 200 system( s.c_str() ); 201 exit(0); 202 } 203 catchDebugger(); 204 } 205 206 #endif 207 208 /* Input data */ 209 if(argc > 1 ){ 210 strcpy(inpfilename,argv[1]); 211 } else { 212 strcpy(inpfilename,"solver.inp"); 213 } 214 ierr = input_fform(inpfilename); 215 if(!ierr){ 216 sprintf(inpfilename,"%d-procs_case/",size); 217 if( chdir( inpfilename ) ) { 218 cerr << "could not change to the problem directory " 219 << inpfilename << endl; 220 return 1; 221 } 222 MPI_Barrier(MPI_COMM_WORLD); 223 setIOparam(); 224 outpar.input_mode = outpar.nsynciofiles; //FIXME this is awful 225 outpar.output_mode = outpar.nsynciofiles; //FIXME this is awful 226 input(); 227 /* now we can start the solver */ 228 proces(); 229 } 230 else{ 231 printf("error during reading ascii input \n"); 232 } 233 MPI_Barrier(MPI_COMM_WORLD); 234 if ( myrank == 0 ) { 235 printf("phasta.cc - last call before finalize!\n"); 236 } 237 return 0; 238 } 239