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