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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1761 - (show annotations)
Mon Sep 8 02:36:47 2008 UTC (10 years, 9 months ago) by gross
File size: 2010 byte(s)
using MPI_Init_thread rather than MPI_Init to clarify the usage with mpi
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 status = MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided );
39 if (status != MPI_SUCCESS) {
40 std::cerr << argv[0] << ": MPI_Init failed, exiting." << std::endl;
41 return status;
42 }
43 mpi_info = Paso_MPIInfo_alloc( MPI_COMM_WORLD );
44
45 if( mpi_info->rank )
46 {
47 char fname[256];
48 sprintf( fname, "stdout_cpu_%04d.out", mpi_info->rank );
49 FILE *fp_out = freopen( fname, "w+", stdout );
50 sprintf( fname, "stdout_cpu_%04d.err", mpi_info->rank );
51 FILE *fp_err = freopen( fname, "w+", stderr );
52 }
53 /*
54 * Start the python parser
55 */
56 status = Py_Main(argc, argv);
57
58 /*
59 * Finalise MPI for a clean exit.
60 */
61 MPI_Finalize();
62
63 Paso_MPIInfo_free( mpi_info );
64 }
65 catch (std::runtime_error &e)
66 {
67 std::cerr << "EXCEPTION: " << e.what() << std::endl;
68 throw;
69 }
70 catch (char *e)
71 {
72 std::cerr << "EXCEPTION: " << e << std::endl;
73 throw;
74 }
75 catch (...)
76 {
77 std::cerr << "EXCEPTION: " << "UNKNOWN." << std::endl;
78 throw;
79 }
80
81 return status;
82 }
83
84 #else
85 int main( int argc, char **argv ) {
86 printf( "Esys must be compiled with PASO_MPI defined to make the MPI version available\n\n" );
87 return 0;
88 }
89 #endif

  ViewVC Help
Powered by ViewVC 1.1.26