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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1556 - (show annotations)
Mon May 12 00:54:58 2008 UTC (12 years, 3 months ago) by gross
File size: 1904 byte(s)
Modification to allow mixed mode execution. 
In order to keep the code portable accross platform all MPI calls within
parallel regions have been moved. 


1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #include <Python.h>
17 #include <mpi.h>
18 #include <iostream>
19 #include <stdexcept>
20
21 extern "C"{
22 #include "paso/Paso_MPI.h"
23 }
24 #ifdef PASO_MPI
25
26 int main( int argc, char **argv ) {
27 int status = 0;
28 int provided;
29 Paso_MPIInfo *mpi_info=NULL;
30 try
31 {
32 /*
33 * Initialise MPI
34 */
35 status = MPI_Init(&argc, &argv);
36 if (status != MPI_SUCCESS) {
37 std::cerr << argv[0] << ": MPI_Init failed, exiting." << std::endl;
38 return status;
39 }
40 mpi_info = Paso_MPIInfo_alloc( MPI_COMM_WORLD );
41
42 if( mpi_info->rank )
43 {
44 char fname[256];
45 sprintf( fname, "stdout_cpu_%04d.out", mpi_info->rank );
46 FILE *fp_out = freopen( fname, "w+", stdout );
47 sprintf( fname, "stdout_cpu_%04d.err", mpi_info->rank );
48 FILE *fp_err = freopen( fname, "w+", stderr );
49 }
50 /*
51 * Start the python parser
52 */
53 status = Py_Main(argc, argv);
54
55 /*
56 * Finalise MPI for a clean exit.
57 */
58 MPI_Finalize();
59
60 Paso_MPIInfo_free( mpi_info );
61 }
62 catch (std::runtime_error &e)
63 {
64 std::cerr << "EXCEPTION: " << e.what() << std::endl;
65 throw;
66 }
67 catch (char *e)
68 {
69 std::cerr << "EXCEPTION: " << e << std::endl;
70 throw;
71 }
72 catch (...)
73 {
74 std::cerr << "EXCEPTION: " << "UNKNOWN." << std::endl;
75 throw;
76 }
77
78 return status;
79 }
80
81 #else
82 int main( int argc, char **argv ) {
83 printf( "Esys must be compiled with PASO_MPI defined to make the MPI version available\n\n" );
84 return 0;
85 }
86 #endif

  ViewVC Help
Powered by ViewVC 1.1.26