1 |
bcumming |
759 |
#include <Python.h> |
2 |
|
|
#include <mpi.h> |
3 |
|
|
#include <iostream> |
4 |
|
|
#include <stdexcept> |
5 |
|
|
|
6 |
|
|
extern "C"{ |
7 |
|
|
#include "paso/Paso.h" |
8 |
|
|
#include "finley/Finley.h" |
9 |
|
|
} |
10 |
|
|
#ifdef PASO_MPI |
11 |
|
|
|
12 |
|
|
int main( int argc, char **argv ) { |
13 |
|
|
int status = 0; |
14 |
|
|
Paso_MPIInfo *mpi_info=NULL; |
15 |
|
|
try |
16 |
|
|
{ |
17 |
|
|
/* |
18 |
|
|
* Initialise MPI |
19 |
|
|
*/ |
20 |
|
|
status = MPI_Init(&argc, &argv); |
21 |
|
|
if (status != MPI_SUCCESS) { |
22 |
|
|
std::cerr << argv[0] << ": MPI_Init failed, exiting." << std::endl; |
23 |
|
|
return status; |
24 |
|
|
} |
25 |
|
|
mpi_info = Paso_MPIInfo_alloc( MPI_COMM_WORLD ); |
26 |
|
|
|
27 |
|
|
if( mpi_info->rank ) |
28 |
|
|
{ |
29 |
|
|
char fname[256]; |
30 |
|
|
|
31 |
|
|
sprintf( fname, "log_P%d.txt", mpi_info->rank ); |
32 |
|
|
FILE *fp = freopen( fname, "w+", stdout ); |
33 |
|
|
} |
34 |
|
|
/* |
35 |
|
|
* Start the python parser |
36 |
|
|
*/ |
37 |
|
|
status = Py_Main(argc, argv); |
38 |
|
|
|
39 |
|
|
/* |
40 |
|
|
* Finalise MPI for a clean exit. |
41 |
|
|
*/ |
42 |
|
|
MPI_Finalize(); |
43 |
|
|
|
44 |
|
|
Paso_MPIInfo_dealloc( mpi_info ); |
45 |
|
|
} |
46 |
|
|
catch (std::runtime_error &e) |
47 |
|
|
{ |
48 |
|
|
std::cerr << "EXCEPTION: " << e.what() << std::endl; |
49 |
|
|
throw; |
50 |
|
|
} |
51 |
|
|
catch (char *e) |
52 |
|
|
{ |
53 |
|
|
std::cerr << "EXCEPTION: " << e << std::endl; |
54 |
|
|
throw; |
55 |
|
|
} |
56 |
|
|
catch (...) |
57 |
|
|
{ |
58 |
|
|
std::cerr << "EXCEPTION: " << "UNKNOWN." << std::endl; |
59 |
|
|
throw; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
return status; |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
#else |
66 |
|
|
int main( int argc, char **argv ) { |
67 |
|
|
printf( "Esys must be compiled with PASO_MPI defined to make the MPI version available\n\n" ); |
68 |
|
|
return 0; |
69 |
|
|
} |
70 |
|
|
#endif |