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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (hide annotations)
Wed Feb 7 02:12:08 2018 UTC (19 months, 1 week ago) by jfenwick
File size: 3025 byte(s)
Make everyone sad by touching all the files

Copyright dates update

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

  ViewVC Help
Powered by ViewVC 1.1.26