/[escript]/trunk/pythonMPI/src/ScriptMPI.cpp
ViewVC logotype

Contents of /trunk/pythonMPI/src/ScriptMPI.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (8 years, 11 months ago) by jfenwick
File size: 2482 byte(s)
Merging dudley and scons updates from branches

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #include <Python.h>
16 #ifdef ESYS_MPI
17 #include <mpi.h>
18 #endif
19 #include <iostream>
20 #include <stdexcept>
21
22 extern "C"{
23 #include "esysUtils/Esys_MPI.h"
24 }
25 #ifdef ESYS_MPI
26
27 int main( int argc, char **argv ) {
28 int status = 0;
29 int provided;
30 Esys_MPIInfo *mpi_info=NULL;
31 try
32 {
33 /*
34 * Initialise MPI
35 */
36 /* status = MPI_Init(&argc, &argv); */
37 status = MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided );
38 if (status != MPI_SUCCESS) {
39 std::cerr << argv[0] << ": MPI_Init failed, exiting." << std::endl;
40 return status;
41 }
42 mpi_info = Esys_MPIInfo_alloc( MPI_COMM_WORLD );
43
44 if( mpi_info->rank )
45 {
46 FILE *fp_out;
47 #ifdef _WIN32
48 fp_out = freopen( "NUL", "w+", stdout );
49 #else
50 fp_out = freopen( "/dev/null", "w+", stdout );
51 #endif
52 }
53 /*
54 * Start the python parser
55 */
56 status = Py_Main(argc, argv);
57
58 /*
59 * Close down MPI.
60 * status==1 : uncaught python exception
61 * status==2 : invalid python cmd line
62 * status>2 : supposed to be param of sys.exit()
63 * sys.exit doesn't return as it should.
64 *
65 * I have made an exception for 2 because calling MPI_Abort
66 * can display pretty ugly messages for not typing params
67 * properly.
68 */
69 if ((status!=0) && (status!=2))
70 {
71 MPI_Abort(MPI_COMM_WORLD,status);
72 }
73 else
74 {
75 /*
76 * Finalise MPI for a clean exit.
77 */
78 MPI_Finalize();
79 }
80 Esys_MPIInfo_free( mpi_info );
81 }
82 catch (std::runtime_error &e)
83 {
84 std::cerr << "EXCEPTION: " << e.what() << std::endl;
85 MPI_Abort(MPI_COMM_WORLD,1);
86 throw;
87 }
88 catch (char *e)
89 {
90 std::cerr << "EXCEPTION: " << e << std::endl;
91 MPI_Abort(MPI_COMM_WORLD,1);
92 throw;
93 }
94 catch (...)
95 {
96 std::cerr << "EXCEPTION: " << "UNKNOWN." << std::endl;
97 MPI_Abort(MPI_COMM_WORLD,1);
98 throw;
99 }
100
101 return status;
102 }
103
104 #else
105 int main( int argc, char **argv ) {
106 printf( "Esys must be compiled with ESYS_MPI defined to make the MPI version available\n\n" );
107 return 0;
108 }
109 #endif

  ViewVC Help
Powered by ViewVC 1.1.26