Salome HOME
ENV: Windows porting.
[modules/kernel.git] / src / MPIContainer / SALOME_MPIContainer.cxx
1 #include <iostream>
2 #include "MPIContainer_i.hxx"
3 #include "Utils_ORB_INIT.hxx"
4 #include "Utils_SINGLETON.hxx"
5 #include "utilities.h"
6 #include <mpi.h>
7 #include "SALOMETraceCollector.hxx"
8 using namespace std;
9
10 int main(int argc, char* argv[])
11 {
12   int nbproc, numproc;
13   Engines_MPIContainer_i * myContainer=NULL;
14
15   MPI_Init(&argc,&argv);
16   MPI_Comm_size(MPI_COMM_WORLD,&nbproc);
17   MPI_Comm_rank(MPI_COMM_WORLD,&numproc);
18
19   // Initialise the ORB.
20   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
21   CORBA::ORB_var &orb = init( argc , argv ) ;
22   SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
23  
24   BEGIN_OF("[" << numproc << "] " << argv[0])
25   try {
26     
27     // Obtain a reference to the root POA.
28     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
29     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
30
31     // obtain the root poa manager
32     PortableServer::POAManager_var pman = root_poa->the_POAManager();
33
34     // define policy objects     
35     PortableServer::ImplicitActivationPolicy_var implicitActivation =
36       root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION) ;
37
38       // default = NO_IMPLICIT_ACTIVATION
39     PortableServer::ThreadPolicy_var threadPolicy =
40       root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL) ;
41       // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
42
43     // create policy list
44     CORBA::PolicyList policyList;
45     policyList.length(2);
46     policyList[0] = PortableServer::ImplicitActivationPolicy::_duplicate(implicitActivation) ;
47     policyList[1] = PortableServer::ThreadPolicy::_duplicate(threadPolicy) ;
48
49     // create the child POA
50     PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil() ;
51     PortableServer::POA_var factory_poa =
52       root_poa->create_POA("factory_poa", pman, policyList) ;
53       //with nil_mgr instead of pman, a new POA manager is created with the new POA
54     
55     // destroy policy objects
56     implicitActivation->destroy() ;
57     threadPolicy->destroy() ;
58
59     char *containerName = "";
60     if (argc >1) 
61     {
62         containerName = argv[1] ;
63     }
64
65     MESSAGE("[" << numproc << "] MPIContainer: load MPIContainer servant");
66     myContainer = new Engines_MPIContainer_i(nbproc,numproc,orb,factory_poa, containerName,argc,argv);
67
68     pman->activate();
69
70     orb->run();
71
72   }
73   catch(CORBA::SystemException&){
74     INFOS("Caught CORBA::SystemException.");
75   }
76   catch(PortableServer::POA::WrongPolicy&){
77     INFOS("Caught CORBA::WrongPolicyException.");
78   }
79   catch(PortableServer::POA::ServantAlreadyActive&){
80     INFOS("Caught CORBA::ServantAlreadyActiveException");
81   }
82   catch(CORBA::Exception&){
83     INFOS("Caught CORBA::Exception.");
84   }
85   catch(...){
86     INFOS("Caught unknown exception.");
87   }
88
89   if(myContainer)
90     delete myContainer;
91
92   END_OF("[" << numproc << "] " << argv[0]);
93   delete myThreadTrace;
94
95   MPI_Finalize();
96
97 }
98