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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2376 - (hide annotations)
Tue Apr 7 06:21:31 2009 UTC (12 years, 3 months ago) by gross
File size: 1995 byte(s)
output form others than the master process can now be switched off (stderr is still redirected to master)
1 gross 2376
2     /*******************************************************
3     *
4     * Copyright (c) 2003-2008 by University of Queensland
5     * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13    
14    
15     #include <Python.h>
16     #ifdef PASO_MPI
17     #include <mpi.h>
18     #endif
19     #include <iostream>
20     #include <stdexcept>
21    
22     extern "C"{
23     #include "paso/Paso_MPI.h"
24     }
25     #ifdef PASO_MPI
26    
27     int main( int argc, char **argv ) {
28     int status = 0;
29     int provided;
30     Paso_MPIInfo *mpi_info=NULL;
31     try
32     {
33     /*
34     * Initialise MPI
35     */
36     /* status = MPI_Init(&argc, &argv); */
37     status = MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided );
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_%04d.out", mpi_info->rank );
48     FILE *fp_out;
49     fp_out = freopen( fname, "w+", stdout );
50     sprintf( fname, "stdout_%04d.err", mpi_info->rank );
51     FILE *fp_err;
52     fp_err = freopen( fname, "w+", stderr );
53     }
54     /*
55     * Start the python parser
56     */
57     status = Py_Main(argc, argv);
58    
59     /*
60     * Finalise MPI for a clean exit.
61     */
62     MPI_Finalize();
63    
64     Paso_MPIInfo_free( mpi_info );
65     }
66     catch (std::runtime_error &e)
67     {
68     std::cerr << "EXCEPTION: " << e.what() << std::endl;
69     throw;
70     }
71     catch (char *e)
72     {
73     std::cerr << "EXCEPTION: " << e << std::endl;
74     throw;
75     }
76     catch (...)
77     {
78     std::cerr << "EXCEPTION: " << "UNKNOWN." << std::endl;
79     throw;
80     }
81    
82     return status;
83     }
84    
85     #else
86     int main( int argc, char **argv ) {
87     printf( "Esys must be compiled with PASO_MPI defined to make the MPI version available\n\n" );
88     return 0;
89     }
90     #endif

  ViewVC Help
Powered by ViewVC 1.1.26