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