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