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