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 #if !(defined IOSTREAMH) 13 #include <iostream> 14 #include <sstream> 15 using namespace std; 16 #endif 17 18 #include <FCMangle.h> 19 #define input FortranCInterface_GLOBAL_(input,INPUT) 20 #define proces FortranCInterface_GLOBAL_(proces,PROCES) 21 #define timer FortranCInterface_GLOBAL_(timer,TIMER) 22 23 #ifdef intel 24 #include <direct.h> 25 #define chdir _chdir 26 #else 27 #include <unistd.h> 28 #endif 29 30 extern "C" char phasta_iotype[80]; 31 char phasta_iotype[80]; 32 33 extern int SONFATH; 34 extern "C" void proces(); 35 extern "C" void input(); 36 extern int input_fform(char inpfname[]); 37 extern void setIOparam(); // For SyncIO 38 39 int myrank; /* made file global for ease in debugging */ 40 41 void 42 catchDebugger() { 43 while (1) { 44 int debuggerPresent=0; 45 int fakeSTOP = 1; // please stop HERE and assign as next line 46 // assign or set debuggerPresent=1 47 if(debuggerPresent) { 48 break; 49 } 50 } 51 } 52 53 // some useful debugging functions 54 55 void 56 pdarray( void* darray , int start, int end ) { 57 for( int i=start; i < end; i++ ){ 58 cout << ((double*)darray)[i] << endl; 59 } 60 } 61 62 void 63 piarray( void* iarray , int start, int end ) { 64 for( int i=start; i < end; i++ ){ 65 cout << ((int*)iarray)[i] << endl; 66 } 67 } 68 69 extern "C" int 70 phasta( int argc, 71 char *argv[] ) { 72 73 int size,ierr; 74 char inpfilename[100]; 75 char* pauseDebugger = getenv("catchDebugger"); 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 #if (defined WIN32) 87 if(argc > 2 ){ 88 catchDebugger(); 89 } 90 #endif 91 #if (1) // ALWAYS ( defined LAUNCH_GDB ) && !( defined WIN32 ) 92 93 if ( pauseDebugger ) { 94 95 int parent_pid = getpid(); 96 int gdb_child = fork(); 97 cout << "gdb_child" << gdb_child << endl; 98 99 if( gdb_child == 0 ) { 100 101 cout << "Debugger Process initiating" << endl; 102 stringstream exec_string; 103 104 #if ( defined decalp ) 105 exec_string <<"xterm -e idb " 106 << " -pid "<< parent_pid <<" "<< argv[0] << endl; 107 #endif 108 #if ( defined LINUX ) 109 exec_string <<"xterm -e gdb" 110 << " -pid "<< parent_pid <<" "<< argv[0] << endl; 111 #endif 112 #if ( defined SUN4 ) 113 exec_string <<"xterm -e dbx " 114 << " - "<< parent_pid <<" "<< argv[0] << endl; 115 #endif 116 #if ( defined IRIX ) 117 exec_string <<"xterm -e dbx " 118 << " -p "<< parent_pid <<" "<< argv[0] << endl; 119 #endif 120 string s = exec_string.str(); 121 system( s.c_str() ); 122 exit(0); 123 } 124 catchDebugger(); 125 } 126 127 #endif 128 129 /* Input data */ 130 if(argc > 1 ){ 131 strcpy(inpfilename,argv[1]); 132 } else { 133 strcpy(inpfilename,"solver.inp"); 134 } 135 ierr = input_fform(inpfilename); 136 if(!ierr){ 137 sprintf(inpfilename,"%d-procs_case/",size); 138 if( chdir( inpfilename ) ) { 139 cerr << "could not change to the problem directory " 140 << inpfilename << endl; 141 return 1; 142 } 143 MPI_Barrier(MPI_COMM_WORLD); 144 setIOparam(); 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 MPI_Finalize(); 157 return 0; 158 } 159