Salome HOME
Copyrights update
[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 #include "SALOMETraceCollector.hxx"
27 using namespace std;
28
29 int main(int argc, char* argv[])
30 {
31   int nbproc, numproc;
32   Engines_MPIContainer_i * myContainer=NULL;
33
34   MPI_Init(&argc,&argv);
35   MPI_Comm_size(MPI_COMM_WORLD,&nbproc);
36   MPI_Comm_rank(MPI_COMM_WORLD,&numproc);
37
38   // Initialise the ORB.
39   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
40   CORBA::ORB_var &orb = init( argc , argv ) ;
41   //  SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
42  
43   BEGIN_OF("[" << numproc << "] " << argv[0])
44   try {
45     
46     // Obtain a reference to the root POA.
47     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
48     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
49
50     // obtain the root poa manager
51     PortableServer::POAManager_var pman = root_poa->the_POAManager();
52
53     // define policy objects     
54     PortableServer::ImplicitActivationPolicy_var implicitActivation =
55       root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION) ;
56
57       // default = NO_IMPLICIT_ACTIVATION
58     PortableServer::ThreadPolicy_var threadPolicy =
59       root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL) ;
60       // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
61
62     // create policy list
63     CORBA::PolicyList policyList;
64     policyList.length(2);
65     policyList[0] = PortableServer::ImplicitActivationPolicy::_duplicate(implicitActivation) ;
66     policyList[1] = PortableServer::ThreadPolicy::_duplicate(threadPolicy) ;
67
68     // create the child POA
69     PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil() ;
70     PortableServer::POA_var factory_poa =
71       root_poa->create_POA("factory_poa", pman, policyList) ;
72       //with nil_mgr instead of pman, a new POA manager is created with the new POA
73     
74     // destroy policy objects
75     implicitActivation->destroy() ;
76     threadPolicy->destroy() ;
77
78     char *containerName = "";
79     if (argc >1) 
80     {
81         containerName = argv[1] ;
82     }
83
84     MESSAGE("[" << numproc << "] MPIContainer: load MPIContainer servant");
85     myContainer = new Engines_MPIContainer_i(nbproc,numproc,orb,factory_poa, containerName,argc,argv);
86
87     pman->activate();
88
89     orb->run();
90
91   }
92   catch(CORBA::SystemException&){
93     INFOS("Caught CORBA::SystemException.");
94   }
95   catch(PortableServer::POA::WrongPolicy&){
96     INFOS("Caught CORBA::WrongPolicyException.");
97   }
98   catch(PortableServer::POA::ServantAlreadyActive&){
99     INFOS("Caught CORBA::ServantAlreadyActiveException");
100   }
101   catch(CORBA::Exception&){
102     INFOS("Caught CORBA::Exception.");
103   }
104   catch(...){
105     INFOS("Caught unknown exception.");
106   }
107
108   if(myContainer)
109     delete myContainer;
110
111   END_OF("[" << numproc << "] " << argv[0]);
112   //  delete myThreadTrace;
113
114   MPI_Finalize();
115
116 }
117