xref: /phasta/phSolver/common/phasta.cc (revision f326e5ce1c9ec3d42b458e4d70e8f1a4847fbc77)
1 #define OMPI_SKIP_MPICXX 1
2 #include <mpi.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 
10 #include "common_c.h"
11 
12 #include "phstream.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 extern void setIOparam(); // For SyncIO
40 
41 int myrank; /* made file global for ease in debugging */
42 
43 void
44 catchDebugger() {
45     while (1) {
46       int debuggerPresent=0;
47       int fakeSTOP = 1; // please stop HERE and assign as next line
48       // assign or set debuggerPresent=1
49       if(debuggerPresent) {
50         break;
51       }
52     }
53 }
54 
55 // some useful debugging functions
56 
57 void
58 pdarray( void* darray , int start, int end ) {
59     for( int i=start; i < end; i++ ){
60         cout << ((double*)darray)[i] << endl;
61     }
62 }
63 
64 void
65 piarray( void* iarray , int start, int end ) {
66     for( int i=start; i < end; i++ ){
67         cout << ((int*)iarray)[i] << endl;
68     }
69 }
70 
71 int phasta( int argc,
72         char *argv[],
73         GRStream* grs) {
74   return 0;
75 }
76 
77 
78 int phasta( int argc,
79         char *argv[] ) {
80 
81     int size,ierr;
82     char inpfilename[100];
83     char* pauseDebugger = getenv("catchDebugger");
84     int initialized;
85     MPI_Initialized(&initialized);
86     if( !initialized )
87       MPI_Init(&argc,&argv);
88     MPI_Comm_size (MPI_COMM_WORLD, &size);
89     MPI_Comm_rank (MPI_COMM_WORLD, &myrank);
90 
91     workfc.numpe = size;
92     workfc.myrank = myrank;
93 
94 #if (defined WIN32)
95     if(argc > 2 ){
96       catchDebugger();
97     }
98 #endif
99 #if (1) // ALWAYS ( defined LAUNCH_GDB ) && !( defined WIN32 )
100 
101     if ( pauseDebugger ) {
102 
103         int parent_pid = getpid();
104         int gdb_child = fork();
105         cout << "gdb_child" << gdb_child << endl;
106 
107         if( gdb_child == 0 ) {
108 
109             cout << "Debugger Process initiating" << endl;
110             stringstream exec_string;
111 
112 #if ( defined decalp )
113             exec_string <<"xterm -e idb "
114                         << " -pid "<< parent_pid <<" "<< argv[0] << endl;
115 #endif
116 #if ( defined LINUX )
117             exec_string <<"xterm -e gdb"
118                         << " -pid "<< parent_pid <<" "<< argv[0] << endl;
119 #endif
120 #if ( defined SUN4 )
121             exec_string <<"xterm -e dbx "
122                         << " - "<< parent_pid <<" "<< argv[0] << endl;
123 #endif
124 #if ( defined IRIX )
125             exec_string <<"xterm -e dbx "
126                         << " -p "<< parent_pid <<" "<< argv[0] << endl;
127 #endif
128             string s = exec_string.str();
129             system( s.c_str() );
130             exit(0);
131         }
132         catchDebugger();
133     }
134 
135 #endif
136 
137     /* Input data  */
138     if(argc > 1 ){
139         strcpy(inpfilename,argv[1]);
140     } else {
141         strcpy(inpfilename,"solver.inp");
142     }
143     ierr = input_fform(inpfilename);
144     if(!ierr){
145       sprintf(inpfilename,"%d-procs_case/",size);
146       if( chdir( inpfilename ) ) {
147         cerr << "could not change to the problem directory "
148           << inpfilename << endl;
149         return 1;
150       }
151       MPI_Barrier(MPI_COMM_WORLD);
152         setIOparam();
153         input();
154         /* now we can start the solver */
155         proces();
156     }
157     else{
158         printf("error during reading ascii input \n");
159     }
160     MPI_Barrier(MPI_COMM_WORLD);
161     if ( myrank == 0 ) {
162       printf("phasta.cc - last call before finalize!\n");
163     }
164     MPI_Finalize();
165     return 0;
166 }
167