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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3522 - (show annotations)
Tue May 24 00:57:58 2011 UTC (8 years, 4 months ago) by gross
File size: 2541 byte(s)
(almost) full support for Point elements
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 #include <iostream>
17 #include <stdexcept>
18
19 extern "C"{
20 #include "esysUtils/Esys_MPI.h"
21 }
22
23 #ifdef ESYS_MPI
24
25 int main( int argc, char **argv ) {
26 int status = 0;
27 int provided;
28 Esys_MPIInfo *mpi_info=NULL;
29 try
30 {
31 /*
32 * Initialise MPI
33 */
34 /* status = MPI_Init(&argc, &argv); */
35 status = MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided );
36 if (status != MPI_SUCCESS) {
37 std::cerr << argv[0] << ": MPI_Init failed, exiting." << std::endl;
38 return status;
39 }
40 mpi_info = Esys_MPIInfo_alloc( MPI_COMM_WORLD );
41
42 if( mpi_info->rank )
43 {
44 #ifdef _WIN32
45 if ( freopen( "NUL", "w+", stdout ) == NULL ) {
46 exit(EXIT_FAILURE);
47 }
48 #else
49 if ( freopen( "/dev/null", "w+", stdout ) == NULL ) {
50 exit(EXIT_FAILURE);
51 }
52 #endif
53 }
54 /*
55 * Start the python parser
56 */
57 status = Py_Main(argc, argv);
58
59 /*
60 * Close down MPI.
61 * status==1 : uncaught python exception
62 * status==2 : invalid python cmd line
63 * status>2 : supposed to be param of sys.exit()
64 * sys.exit doesn't return as it should.
65 *
66 * I have made an exception for 2 because calling MPI_Abort
67 * can display pretty ugly messages for not typing params
68 * properly.
69 */
70 if ((status!=0) && (status!=2))
71 {
72 MPI_Abort(MPI_COMM_WORLD,status);
73 }
74 else
75 {
76 /*
77 * Finalise MPI for a clean exit.
78 */
79 MPI_Finalize();
80 }
81 Esys_MPIInfo_free( mpi_info );
82 }
83 catch (std::runtime_error &e)
84 {
85 std::cerr << "EXCEPTION: " << e.what() << std::endl;
86 MPI_Abort(MPI_COMM_WORLD,1);
87 throw;
88 }
89 catch (char *e)
90 {
91 std::cerr << "EXCEPTION: " << e << std::endl;
92 MPI_Abort(MPI_COMM_WORLD,1);
93 throw;
94 }
95 catch (...)
96 {
97 std::cerr << "EXCEPTION: " << "UNKNOWN." << std::endl;
98 MPI_Abort(MPI_COMM_WORLD,1);
99 throw;
100 }
101
102 return status;
103 }
104
105 #else
106
107 int main( int argc, char **argv ) {
108 printf( "Esys must be compiled with ESYS_MPI defined to make the MPI version available\n\n" );
109 return 0;
110 }
111 #endif // ESYS_MPI
112

  ViewVC Help
Powered by ViewVC 1.1.26