xref: /phasta/phSolver/common/phasta.cc (revision f1ff48b0dc8b3d7cb993a2e35bb9deededfc862f)
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 "common_c.h"
13 
14 #if !(defined IOSTREAMH)
15 #include <iostream>
16 #include <sstream>
17 using namespace std;
18 #endif
19 
20 #include <FCMangle.h>
21 #define input FortranCInterface_GLOBAL_(input,INPUT)
22 #define proces FortranCInterface_GLOBAL_(proces,PROCES)
23 #define timer FortranCInterface_GLOBAL_(timer,TIMER)
24 
25 #ifdef intel
26 #include <direct.h>
27 #define chdir _chdir
28 #else
29 #include <unistd.h>
30 #endif
31 
32 extern "C" char phasta_iotype[80];
33 char phasta_iotype[80];
34 
35 extern int SONFATH;
36 extern "C" void proces();
37 extern "C" void input();
38 extern int input_fform(char inpfname[]);
39 //MR CHANGE
40 extern void setIOparam(); // For SyncIO
41 //MR CHANGE END
42 
43 int myrank; /* made file global for ease in debugging */
44 
45 void
46 catchDebugger() {
47     while (1) {
48       int debuggerPresent=0;
49       int fakeSTOP = 1; // please stop HERE and assign as next line
50       // assign or set debuggerPresent=1
51       if(debuggerPresent) {
52         break;
53       }
54     }
55 }
56 
57 // some useful debugging functions
58 
59 void
60 pdarray( void* darray , int start, int end ) {
61     for( int i=start; i < end; i++ ){
62         cout << ((double*)darray)[i] << endl;
63     }
64 }
65 
66 void
67 piarray( void* iarray , int start, int end ) {
68     for( int i=start; i < end; i++ ){
69         cout << ((int*)iarray)[i] << endl;
70     }
71 }
72 
73 extern "C" int
74 phasta( int argc,
75         char *argv[] ) {
76 
77     int size,ierr;
78     char inpfilename[100];
79     char* pauseDebugger = getenv("catchDebugger");
80     //cout << "pauseDebugger" << pauseDebugger << endl;
81 
82     MPI_Init(&argc,&argv);
83     MPI_Comm_size (MPI_COMM_WORLD, &size);
84     MPI_Comm_rank (MPI_COMM_WORLD, &myrank);
85 
86     workfc.numpe = size;
87     workfc.myrank = myrank;
88 
89 #if (defined WIN32)
90     if(argc > 2 ){
91       catchDebugger();
92     }
93 #endif
94 #if (1) // ALWAYS ( defined LAUNCH_GDB ) && !( defined WIN32 )
95 
96     if ( pauseDebugger ) {
97 
98         int parent_pid = getpid();
99         int gdb_child = fork();
100         cout << "gdb_child" << gdb_child << endl;
101 
102         if( gdb_child == 0 ) {
103 
104             cout << "Debugger Process initiating" << endl;
105             stringstream exec_string;
106 
107 #if ( defined decalp )
108             exec_string <<"xterm -e idb "
109                         << " -pid "<< parent_pid <<" "<< argv[0] << endl;
110 #endif
111 #if ( defined LINUX )
112             exec_string <<"xterm -e gdb"
113                         << " -pid "<< parent_pid <<" "<< argv[0] << endl;
114 #endif
115 #if ( defined SUN4 )
116             exec_string <<"xterm -e dbx "
117                         << " - "<< parent_pid <<" "<< argv[0] << endl;
118 #endif
119 #if ( defined IRIX )
120             exec_string <<"xterm -e dbx "
121                         << " -p "<< parent_pid <<" "<< argv[0] << endl;
122 #endif
123             string s = exec_string.str();
124             system( s.c_str() );
125             exit(0);
126         }
127         catchDebugger();
128     }
129 
130 #endif
131 
132     /* Input data  */
133     if(argc > 1 ){
134         strcpy(inpfilename,argv[1]);
135     } else {
136         strcpy(inpfilename,"solver.inp");
137     }
138     ierr = input_fform(inpfilename);
139     if(!ierr){
140       sprintf(inpfilename,"%d-procs_case/",size);
141       if( chdir( inpfilename ) ) {
142         cerr << "could not change to the problem directory "
143           << inpfilename << endl;
144         return 1;
145       }
146       MPI_Barrier(MPI_COMM_WORLD);
147 
148 //MR CHANGE
149         setIOparam();
150 //MR CHANGE END
151 
152         input();
153         /* now we can start the solver */
154         proces();
155     }
156     else{
157         printf("error during reading ascii input \n");
158     }
159 
160 //MR CHANGE
161 
162     MPI_Barrier(MPI_COMM_WORLD);
163     if ( myrank == 0 ) {
164       printf("phasta.cc - last call before finalize!\n");
165     }
166 //MR CHANGE
167 
168     MPI_Finalize();
169     return 0;
170 }
171