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 157 } 158 159 int phasta( int argc, 160 char *argv[] ) { 161 int size,ierr; 162 char inpfilename[100]; 163 char* pauseDebugger = getenv("catchDebugger"); 164 MPI_Comm_size (MPI_COMM_WORLD, &size); 165 MPI_Comm_rank (MPI_COMM_WORLD, &myrank); 166 167 workfc.numpe = size; 168 workfc.myrank = myrank; 169 170 #if (defined WIN32) 171 if(argc > 2 ){ 172 catchDebugger(); 173 } 174 #endif 175 #if (1) // ALWAYS ( defined LAUNCH_GDB ) && !( defined WIN32 ) 176 177 if ( pauseDebugger ) { 178 179 int parent_pid = getpid(); 180 int gdb_child = fork(); 181 cout << "gdb_child" << gdb_child << endl; 182 183 if( gdb_child == 0 ) { 184 185 cout << "Debugger Process initiating" << endl; 186 stringstream exec_string; 187 188 #if ( defined decalp ) 189 exec_string <<"xterm -e idb " 190 << " -pid "<< parent_pid <<" "<< argv[0] << endl; 191 #endif 192 #if ( defined LINUX ) 193 exec_string <<"xterm -e gdb" 194 << " -pid "<< parent_pid <<" "<< argv[0] << endl; 195 #endif 196 #if ( defined SUN4 ) 197 exec_string <<"xterm -e dbx " 198 << " - "<< parent_pid <<" "<< argv[0] << endl; 199 #endif 200 #if ( defined IRIX ) 201 exec_string <<"xterm -e dbx " 202 << " -p "<< parent_pid <<" "<< argv[0] << endl; 203 #endif 204 string s = exec_string.str(); 205 system( s.c_str() ); 206 exit(0); 207 } 208 catchDebugger(); 209 } 210 211 #endif 212 213 /* Input data */ 214 if(argc > 1 ){ 215 strcpy(inpfilename,argv[1]); 216 } else { 217 strcpy(inpfilename,"solver.inp"); 218 } 219 ierr = input_fform(inpfilename); 220 if(!ierr){ 221 sprintf(inpfilename,"%d-procs_case/",size); 222 if( chdir( inpfilename ) ) { 223 cerr << "could not change to the problem directory " 224 << inpfilename << endl; 225 return 1; 226 } 227 MPI_Barrier(MPI_COMM_WORLD); 228 setIOparam(); 229 outpar.input_mode = outpar.nsynciofiles; //FIXME this is awful 230 outpar.output_mode = outpar.nsynciofiles; //FIXME this is awful 231 input(); 232 /* now we can start the solver */ 233 proces(); 234 } 235 else{ 236 printf("error during reading ascii input \n"); 237 } 238 MPI_Barrier(MPI_COMM_WORLD); 239 if ( myrank == 0 ) { 240 printf("phasta.cc - last call before finalize!\n"); 241 } 242 return 0; 243 } 244