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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4963 - (show annotations)
Fri May 23 05:12:40 2014 UTC (7 years ago) by jfenwick
File size: 3034 byte(s)
Removed JMPI from ScriptMPI.cpp.
Changed options file to build shared libraries.
Fixed error in unit tests


1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17
18 #include <Python.h>
19 #include <iostream>
20 #include <stdexcept>
21
22 #include "esysUtils/Esys_MPI.h"
23
24 #ifdef ESYS_MPI
25
26 int main( int argc, char **argv ) {
27 int status = 0;
28 int provided;
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 int rank=0;
41 if (MPI_Comm_rank(MPI_COMM_WORLD, &rank)!=MPI_SUCCESS)
42 {
43 MPI_Abort(MPI_COMM_WORLD, 1);
44 }
45
46 if( rank )
47 {
48 #ifdef _WIN32
49 if ( freopen( "NUL", "w+", stdout ) == NULL ) {
50 exit(EXIT_FAILURE);
51 }
52 #else
53 if ( freopen( "/dev/null", "w+", stdout ) == NULL ) {
54 exit(EXIT_FAILURE);
55 }
56 #endif
57 }
58 /*
59 * Start the python parser
60 */
61
62 #ifdef ESPYTHON3
63 wchar_t** wargv=new wchar_t*[argc+1];
64 for (int i=0;i<argc;++i)
65 {
66 int len=strlen(argv[i]);
67 wargv[i]=new wchar_t[len+1];
68 for (int j=0;j<len;++j)
69 {
70 wargv[i][j]=wchar_t(argv[i][j]);
71 }
72 wargv[i][len]=0;
73 }
74 wargv[argc]=0;
75 status = Py_Main(argc, wargv);
76 #else
77
78
79 status = Py_Main(argc, argv);
80 #endif
81 /*
82 * Close down MPI.
83 * status==1 : uncaught python exception
84 * status==2 : invalid python cmd line
85 * status>2 : supposed to be param of sys.exit()
86 * sys.exit doesn't return as it should.
87 *
88 * I have made an exception for 2 because calling MPI_Abort
89 * can display pretty ugly messages for not typing params
90 * properly.
91 */
92 if ((status!=0) && (status!=2))
93 {
94 MPI_Abort(MPI_COMM_WORLD,status);
95 }
96 else
97 {
98 /*
99 * Finalise MPI for a clean exit.
100 */
101 MPI_Finalize();
102 }
103 }
104 catch (std::runtime_error &e)
105 {
106 std::cerr << "EXCEPTION: " << e.what() << std::endl;
107 MPI_Abort(MPI_COMM_WORLD,1);
108 throw;
109 }
110 catch (char *e)
111 {
112 std::cerr << "EXCEPTION: " << e << std::endl;
113 MPI_Abort(MPI_COMM_WORLD,1);
114 throw;
115 }
116 catch (...)
117 {
118 std::cerr << "EXCEPTION: " << "UNKNOWN." << std::endl;
119 MPI_Abort(MPI_COMM_WORLD,1);
120 throw;
121 }
122
123 return status;
124 }
125
126 #else
127
128 int main( int argc, char **argv ) {
129 printf( "Esys must be compiled with ESYS_MPI defined to make the MPI version available\n\n" );
130 return 0;
131 }
132 #endif // ESYS_MPI
133

  ViewVC Help
Powered by ViewVC 1.1.26