xref: /phasta/M2N/src/phasta.cc (revision 16223cb9c3f88b34f2cb94151b5cf5ffc1aac5e2)
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 "commonM2N_c.h"
13 
14 #if !(defined IOSTREAMH)
15 #include <iostream>
16 #include <strstream>
17 using namespace std;
18 #endif
19 
20 #include <FCMangle.h>
21 #define input FortranCInterface_GLOBAL_(input,INPUT)
22 #define timer FortranCInterface_GLOBAL_(timer,TIMER)
23 
24 #ifdef intel
25 #include <direct.h>
26 #define chdir _chdir
27 #else
28 #include <unistd.h>
29 #endif
30 
31 extern "C" char phasta_iotype[80];
32 char phasta_iotype[80];
33 
34 extern "C" void input();
35 //MR CHANGE
36 extern void setIOparam(); // For SyncIO
37 //MR CHANGE END
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     //cout << "pauseDebugger" << pauseDebugger << endl;
77 
78     MPI_Init(&argc,&argv);
79     MPI_Comm_size (MPI_COMM_WORLD, &size);
80     MPI_Comm_rank (MPI_COMM_WORLD, &myrank);
81 
82     workfc.numpe = size;
83     workfc.myrank = myrank;
84 
85 #if (defined WIN32)
86     if(argc > 2 ){
87       catchDebugger();
88     }
89 #endif
90 #if (1) // ALWAYS ( defined LAUNCH_GDB ) && !( defined WIN32 )
91 
92     if ( pauseDebugger ) {
93 
94         int parent_pid = getpid();
95         int gdb_child = fork();
96         cout << "gdb_child" << gdb_child << endl;
97 
98         if( gdb_child == 0 ) {
99 
100             cout << "Debugger Process initiating" << endl;
101             strstream exec_string;
102 
103 #if ( defined decalp )
104             exec_string <<"xterm -e idb "
105                         << " -pid "<< parent_pid <<" "<< argv[0] << endl;
106 #endif
107 #if ( defined LINUX )
108             exec_string <<"xterm -e gdb"
109                         << " -pid "<< parent_pid <<" "<< argv[0] << endl;
110 #endif
111 #if ( defined SUN4 )
112             exec_string <<"xterm -e dbx "
113                         << " - "<< parent_pid <<" "<< argv[0] << endl;
114 #endif
115 #if ( defined IRIX )
116             exec_string <<"xterm -e dbx "
117                         << " -p "<< parent_pid <<" "<< argv[0] << endl;
118 #endif
119             system( exec_string.str() );
120             exit(0);
121         }
122         catchDebugger();
123     }
124 
125 #endif
126 
127 //MR CHANGE
128         setIOparam();
129 //MR CHANGE END
130 
131         input();
132 //MR CHANGE
133 
134     MPI_Barrier(MPI_COMM_WORLD);
135     if ( myrank == 0 ) {
136       printf("phasta.cc - last call before finalize!\n");
137     }
138 //MR CHANGE
139 
140     MPI_Finalize();
141     return 0;
142 }
143