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