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 fprintf(stderr, "HEY! if you see this email Cameron and tell him " 75 "to implement %s(...) on line %d of %s " 76 "... returning an error\n", __func__, __LINE__, __FILE__); 77 return 1; 78 } 79 80 int phasta(int argc, 81 char *argv[], 82 RStream* rs) { 83 fprintf(stderr, "HEY! if you see this email Cameron and tell him " 84 "to implement %s(...) on line %d of %s " 85 "... returning an error\n", __func__, __LINE__, __FILE__); 86 return 1; 87 } 88 89 int phasta(int argc, 90 char *argv[], 91 GRStream* grs, 92 RStream* rs) { 93 fprintf(stderr, "HEY! if you see this email Cameron and tell him " 94 "to implement %s(...) on line %d of %s " 95 "... returning an error\n", __func__, __LINE__, __FILE__); 96 return 1; 97 } 98 99 int phasta( int argc, 100 char *argv[] ) { 101 102 int size,ierr; 103 char inpfilename[100]; 104 char* pauseDebugger = getenv("catchDebugger"); 105 int initialized; 106 MPI_Initialized(&initialized); 107 if( !initialized ) 108 MPI_Init(&argc,&argv); 109 MPI_Comm_size (MPI_COMM_WORLD, &size); 110 MPI_Comm_rank (MPI_COMM_WORLD, &myrank); 111 112 workfc.numpe = size; 113 workfc.myrank = myrank; 114 115 #if (defined WIN32) 116 if(argc > 2 ){ 117 catchDebugger(); 118 } 119 #endif 120 #if (1) // ALWAYS ( defined LAUNCH_GDB ) && !( defined WIN32 ) 121 122 if ( pauseDebugger ) { 123 124 int parent_pid = getpid(); 125 int gdb_child = fork(); 126 cout << "gdb_child" << gdb_child << endl; 127 128 if( gdb_child == 0 ) { 129 130 cout << "Debugger Process initiating" << endl; 131 stringstream exec_string; 132 133 #if ( defined decalp ) 134 exec_string <<"xterm -e idb " 135 << " -pid "<< parent_pid <<" "<< argv[0] << endl; 136 #endif 137 #if ( defined LINUX ) 138 exec_string <<"xterm -e gdb" 139 << " -pid "<< parent_pid <<" "<< argv[0] << endl; 140 #endif 141 #if ( defined SUN4 ) 142 exec_string <<"xterm -e dbx " 143 << " - "<< parent_pid <<" "<< argv[0] << endl; 144 #endif 145 #if ( defined IRIX ) 146 exec_string <<"xterm -e dbx " 147 << " -p "<< parent_pid <<" "<< argv[0] << endl; 148 #endif 149 string s = exec_string.str(); 150 system( s.c_str() ); 151 exit(0); 152 } 153 catchDebugger(); 154 } 155 156 #endif 157 158 /* Input data */ 159 if(argc > 1 ){ 160 strcpy(inpfilename,argv[1]); 161 } else { 162 strcpy(inpfilename,"solver.inp"); 163 } 164 ierr = input_fform(inpfilename); 165 if(!ierr){ 166 sprintf(inpfilename,"%d-procs_case/",size); 167 if( chdir( inpfilename ) ) { 168 cerr << "could not change to the problem directory " 169 << inpfilename << endl; 170 return 1; 171 } 172 MPI_Barrier(MPI_COMM_WORLD); 173 setIOparam(); 174 input(); 175 /* now we can start the solver */ 176 proces(); 177 } 178 else{ 179 printf("error during reading ascii input \n"); 180 } 181 MPI_Barrier(MPI_COMM_WORLD); 182 if ( myrank == 0 ) { 183 printf("phasta.cc - last call before finalize!\n"); 184 } 185 MPI_Finalize(); 186 return 0; 187 } 188