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