Salome HOME
DCQ : Merge with Ecole_ete_a6.
[modules/kernel.git] / src / MPIContainer / SALOME_MPIContainer.cxx
1 //  SALOME MPIContainer : implemenation of container based on MPI libraries
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_MPIContainer.cxx
25 //  Module : SALOME
26
27 using namespace std;
28 #include <iostream>
29 #include "MPIContainer_i.hxx"
30 #include "utilities.h"
31 #include <mpi.h>
32
33 int main(int argc, char* argv[])
34 {
35   int nbproc, numproc;
36   MPIContainer_i * myContainer;
37
38   BEGIN_OF(argv[0])
39   try {
40     
41     MESSAGE("Connection MPI");
42
43     MPI_Init(&argc,&argv);
44     MPI_Comm_size(MPI_COMM_WORLD,&nbproc);
45     MPI_Comm_rank(MPI_COMM_WORLD,&numproc);
46
47     MESSAGE("Initialisation CORBA");
48     // Initialise the ORB.
49     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
50  
51     // Obtain a reference to the root POA.
52     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
53     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
54
55     // obtain the root poa manager
56     PortableServer::POAManager_var pman = root_poa->the_POAManager();
57
58     // define policy objects     
59     PortableServer::ImplicitActivationPolicy_var implicitActivation =
60       root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION) ;
61
62       // default = NO_IMPLICIT_ACTIVATION
63     PortableServer::ThreadPolicy_var threadPolicy =
64       root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL) ;
65       // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
66
67     // create policy list
68     CORBA::PolicyList policyList;
69     policyList.length(2);
70     policyList[0] = PortableServer::ImplicitActivationPolicy::_duplicate(implicitActivation) ;
71     policyList[1] = PortableServer::ThreadPolicy::_duplicate(threadPolicy) ;
72
73     // create the child POA
74     PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil() ;
75     PortableServer::POA_var factory_poa =
76       root_poa->create_POA("factory_poa", pman, policyList) ;
77       //with nil_mgr instead of pman, a new POA manager is created with the new POA
78     
79     // destroy policy objects
80     implicitActivation->destroy() ;
81     threadPolicy->destroy() ;
82
83     char *containerName = "";
84     if (argc >1) 
85     {
86         containerName = argv[1] ;
87     }
88
89     MESSAGE("Chargement container sur proc: " << numproc);
90     myContainer = new MPIContainer_i(nbproc,numproc,orb,factory_poa, containerName);
91     MESSAGE("Fin chargement container");
92
93     pman->activate();
94
95     orb->run();
96     orb->destroy();
97
98     delete myContainer;
99     MPI_Finalize();
100   }
101   catch(CORBA::SystemException&) {
102     INFOS("Caught CORBA::SystemException.")
103   }
104   catch(PortableServer::POA::WrongPolicy&)
105   {
106     INFOS("Caught CORBA::WrongPolicyException.")
107   }
108   catch(PortableServer::POA::ServantAlreadyActive&)
109   {
110     INFOS("Caught CORBA::ServantAlreadyActiveException")
111   }
112   catch(CORBA::Exception&) {
113     INFOS("Caught CORBA::Exception.")
114   }
115   catch(...) {
116     INFOS("Caught unknown exception.")
117    }
118   END_OF(argv[0]);
119 }
120