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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6939 - (hide annotations)
Mon Jan 20 03:37:18 2020 UTC (10 months, 2 weeks ago) by uqaeller
File size: 3101 byte(s)
Updated the copyright header.


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

  ViewVC Help
Powered by ViewVC 1.1.26