xref: /phasta/M2N/src/phasta.cc (revision afdb5118dfd2495aeb091efbcf4ec95116844359)
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 
5 #include <unistd.h>
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 
9 #if !(defined IOSTREAMH)
10 #include <iostream>
11 #include <sstream>
12 using namespace std;
13 #endif
14 
15 #define OMPI_SKIP_MPICXX 1
16 #include <mpi.h>
17 
18 #include <FCMangle.h>
19 #define input FortranCInterface_GLOBAL_(input,INPUT)
20 #define timer FortranCInterface_GLOBAL_(timer,TIMER)
21 
22 #include "commonM2N_c.h"
23 
24 extern "C" char phasta_iotype[80];
25 char phasta_iotype[80];
26 
27 extern "C" void input();
28 //MR CHANGE
29 extern void setIOparam(); // For SyncIO
30 //MR CHANGE END
31 
32 int myrank; /* made file global for ease in debugging */
33 
34 void
catchDebugger()35 catchDebugger() {
36     while (1) {
37       int debuggerPresent=0;
38       int fakeSTOP = 1; // please stop HERE and assign as next line
39       // assign or set debuggerPresent=1
40       if(debuggerPresent) {
41         break;
42       }
43     }
44 }
45 
46 // some useful debugging functions
47 
48 void
pdarray(void * darray,int start,int end)49 pdarray( void* darray , int start, int end ) {
50     for( int i=start; i < end; i++ ){
51         cout << ((double*)darray)[i] << endl;
52     }
53 }
54 
55 void
piarray(void * iarray,int start,int end)56 piarray( void* iarray , int start, int end ) {
57     for( int i=start; i < end; i++ ){
58         cout << ((int*)iarray)[i] << endl;
59     }
60 }
61 
62 extern "C" int
phasta(int argc,char * argv[])63 phasta( int argc,
64         char *argv[] ) {
65 
66     int size,ierr;
67     char inpfilename[100];
68     char* pauseDebugger = getenv("catchDebugger");
69     //cout << "pauseDebugger" << pauseDebugger << endl;
70 
71     MPI_Init(&argc,&argv);
72     MPI_Comm_size (MPI_COMM_WORLD, &size);
73     MPI_Comm_rank (MPI_COMM_WORLD, &myrank);
74 
75     workfc.numpe = size;
76     workfc.myrank = myrank;
77 
78 #if (defined WIN32)
79     if(argc > 2 ){
80       catchDebugger();
81     }
82 #endif
83 #if (1) // ALWAYS ( defined LAUNCH_GDB ) && !( defined WIN32 )
84 
85     if ( pauseDebugger ) {
86 
87         int parent_pid = getpid();
88         int gdb_child = fork();
89         cout << "gdb_child" << gdb_child << endl;
90 
91         if( gdb_child == 0 ) {
92 
93             cout << "Debugger Process initiating" << endl;
94             stringstream exec_string;
95 
96 #if ( defined decalp )
97             exec_string <<"xterm -e idb "
98                         << " -pid "<< parent_pid <<" "<< argv[0] << endl;
99 #endif
100 #if ( defined LINUX )
101             exec_string <<"xterm -e gdb"
102                         << " -pid "<< parent_pid <<" "<< argv[0] << endl;
103 #endif
104 #if ( defined SUN4 )
105             exec_string <<"xterm -e dbx "
106                         << " - "<< parent_pid <<" "<< argv[0] << endl;
107 #endif
108 #if ( defined IRIX )
109             exec_string <<"xterm -e dbx "
110                         << " -p "<< parent_pid <<" "<< argv[0] << endl;
111 #endif
112             string cmd = exec_string.str();
113             system( cmd.c_str() );
114             exit(0);
115         }
116         catchDebugger();
117     }
118 
119 #endif
120 
121 //MR CHANGE
122         setIOparam();
123 //MR CHANGE END
124 
125         input();
126 //MR CHANGE
127 
128     MPI_Barrier(MPI_COMM_WORLD);
129     if ( myrank == 0 ) {
130       printf("phasta.cc - last call before finalize!\n");
131     }
132 //MR CHANGE
133 
134     MPI_Finalize();
135     return 0;
136 }
137