1 |
|
2 |
/* $Id$ */ |
3 |
|
4 |
/******************************************************* |
5 |
* |
6 |
* Copyright 2003-2007 by ACceSS MNRF |
7 |
* Copyright 2007 by University of Queensland |
8 |
* |
9 |
* http://esscc.uq.edu.au |
10 |
* Primary Business: Queensland, Australia |
11 |
* Licensed under the Open Software License version 3.0 |
12 |
* http://www.opensource.org/licenses/osl-3.0.php |
13 |
* |
14 |
*******************************************************/ |
15 |
|
16 |
#include <Python.h> |
17 |
#include <mpi.h> |
18 |
#include <iostream> |
19 |
#include <stdexcept> |
20 |
|
21 |
extern "C"{ |
22 |
#include "paso/Paso_MPI.h" |
23 |
} |
24 |
#ifdef PASO_MPI |
25 |
|
26 |
int main( int argc, char **argv ) { |
27 |
int status = 0; |
28 |
Paso_MPIInfo *mpi_info=NULL; |
29 |
try |
30 |
{ |
31 |
/* |
32 |
* Initialise MPI |
33 |
*/ |
34 |
status = MPI_Init(&argc, &argv); |
35 |
if (status != MPI_SUCCESS) { |
36 |
std::cerr << argv[0] << ": MPI_Init failed, exiting." << std::endl; |
37 |
return status; |
38 |
} |
39 |
mpi_info = Paso_MPIInfo_alloc( MPI_COMM_WORLD ); |
40 |
|
41 |
if( mpi_info->rank ) |
42 |
{ |
43 |
char fname[256]; |
44 |
sprintf( fname, "stdout_cpu_%04d.out", mpi_info->rank ); |
45 |
FILE *fp_out = freopen( fname, "w+", stdout ); |
46 |
sprintf( fname, "stdout_cpu_%04d.err", mpi_info->rank ); |
47 |
FILE *fp_err = freopen( fname, "w+", stderr ); |
48 |
} |
49 |
/* |
50 |
* Start the python parser |
51 |
*/ |
52 |
status = Py_Main(argc, argv); |
53 |
|
54 |
/* |
55 |
* Finalise MPI for a clean exit. |
56 |
*/ |
57 |
MPI_Finalize(); |
58 |
|
59 |
Paso_MPIInfo_free( mpi_info ); |
60 |
} |
61 |
catch (std::runtime_error &e) |
62 |
{ |
63 |
std::cerr << "EXCEPTION: " << e.what() << std::endl; |
64 |
throw; |
65 |
} |
66 |
catch (char *e) |
67 |
{ |
68 |
std::cerr << "EXCEPTION: " << e << std::endl; |
69 |
throw; |
70 |
} |
71 |
catch (...) |
72 |
{ |
73 |
std::cerr << "EXCEPTION: " << "UNKNOWN." << std::endl; |
74 |
throw; |
75 |
} |
76 |
|
77 |
return status; |
78 |
} |
79 |
|
80 |
#else |
81 |
int main( int argc, char **argv ) { |
82 |
printf( "Esys must be compiled with PASO_MPI defined to make the MPI version available\n\n" ); |
83 |
return 0; |
84 |
} |
85 |
#endif |