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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1705 - (show annotations)
Thu Aug 14 05:56:40 2008 UTC (13 years, 1 month ago) by ksteube
File size: 1927 byte(s)
Branch scons-dev is hereby closed.
Some parts of scons scripts have been re-written.

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 #ifdef PASO_MPI
18 #include <mpi.h>
19 #endif
20 #include <iostream>
21 #include <stdexcept>
22
23 extern "C"{
24 #include "paso/Paso_MPI.h"
25 }
26 #ifdef PASO_MPI
27
28 int main( int argc, char **argv ) {
29 int status = 0;
30 int provided;
31 Paso_MPIInfo *mpi_info=NULL;
32 try
33 {
34 /*
35 * Initialise MPI
36 */
37 status = MPI_Init(&argc, &argv);
38 if (status != MPI_SUCCESS) {
39 std::cerr << argv[0] << ": MPI_Init failed, exiting." << std::endl;
40 return status;
41 }
42 mpi_info = Paso_MPIInfo_alloc( MPI_COMM_WORLD );
43
44 if( mpi_info->rank )
45 {
46 char fname[256];
47 sprintf( fname, "stdout_cpu_%04d.out", mpi_info->rank );
48 FILE *fp_out = freopen( fname, "w+", stdout );
49 sprintf( fname, "stdout_cpu_%04d.err", mpi_info->rank );
50 FILE *fp_err = freopen( fname, "w+", stderr );
51 }
52 /*
53 * Start the python parser
54 */
55 status = Py_Main(argc, argv);
56
57 /*
58 * Finalise MPI for a clean exit.
59 */
60 MPI_Finalize();
61
62 Paso_MPIInfo_free( mpi_info );
63 }
64 catch (std::runtime_error &e)
65 {
66 std::cerr << "EXCEPTION: " << e.what() << std::endl;
67 throw;
68 }
69 catch (char *e)
70 {
71 std::cerr << "EXCEPTION: " << e << std::endl;
72 throw;
73 }
74 catch (...)
75 {
76 std::cerr << "EXCEPTION: " << "UNKNOWN." << std::endl;
77 throw;
78 }
79
80 return status;
81 }
82
83 #else
84 int main( int argc, char **argv ) {
85 printf( "Esys must be compiled with PASO_MPI defined to make the MPI version available\n\n" );
86 return 0;
87 }
88 #endif

  ViewVC Help
Powered by ViewVC 1.1.26