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