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