Salome HOME
PR: mergefrom_PRAS_br3_06Nov04
[modules/kernel.git] / src / MPIContainer / SALOME_MPIContainer.cxx
1 //  SALOME MPIContainer : implemenation of container based on MPI libraries
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOME_MPIContainer.cxx
25 //  Module : SALOME
26
27 using namespace std;
28 #include <iostream>
29 #include "MPIContainer_i.hxx"
30 #include "utilities.h"
31 #include "LocalTraceCollector.hxx"
32 #include <mpi.h>
33
34 int main(int argc, char* argv[])
35 {
36   LocalTraceCollector *myThreadTrace = LocalTraceCollector::instance();
37   int nbproc, numproc;
38   MPIContainer_i * myContainer;
39
40   BEGIN_OF(argv[0])
41   try {
42     
43     MESSAGE("Connection MPI");
44
45     MPI_Init(&argc,&argv);
46     MPI_Comm_size(MPI_COMM_WORLD,&nbproc);
47     MPI_Comm_rank(MPI_COMM_WORLD,&numproc);
48
49     MESSAGE("Initialisation CORBA");
50     // Initialise the ORB.
51     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
52  
53     // Obtain a reference to the root POA.
54     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
55     PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
56
57     // obtain the root poa manager
58     PortableServer::POAManager_var pman = root_poa->the_POAManager();
59
60     // define policy objects     
61     PortableServer::ImplicitActivationPolicy_var implicitActivation =
62       root_poa->create_implicit_activation_policy(PortableServer::NO_IMPLICIT_ACTIVATION) ;
63
64       // default = NO_IMPLICIT_ACTIVATION
65     PortableServer::ThreadPolicy_var threadPolicy =
66       root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL) ;
67       // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL
68
69     // create policy list
70     CORBA::PolicyList policyList;
71     policyList.length(2);
72     policyList[0] = PortableServer::ImplicitActivationPolicy::_duplicate(implicitActivation) ;
73     policyList[1] = PortableServer::ThreadPolicy::_duplicate(threadPolicy) ;
74
75     // create the child POA
76     PortableServer::POAManager_var nil_mgr = PortableServer::POAManager::_nil() ;
77     PortableServer::POA_var factory_poa =
78       root_poa->create_POA("factory_poa", pman, policyList) ;
79       //with nil_mgr instead of pman, a new POA manager is created with the new POA
80     
81     // destroy policy objects
82     implicitActivation->destroy() ;
83     threadPolicy->destroy() ;
84
85     char *containerName = "";
86     if (argc >1) 
87     {
88         containerName = argv[1] ;
89     }
90
91     MESSAGE("Chargement container sur proc: " << numproc);
92     myContainer = new MPIContainer_i(nbproc,numproc,orb,factory_poa, containerName);
93     MESSAGE("Fin chargement container");
94
95     pman->activate();
96
97     orb->run();
98     orb->destroy();
99
100     delete myContainer;
101     MPI_Finalize();
102   }
103   catch(CORBA::SystemException&) {
104     INFOS("Caught CORBA::SystemException.")
105   }
106   catch(PortableServer::POA::WrongPolicy&)
107   {
108     INFOS("Caught CORBA::WrongPolicyException.")
109   }
110   catch(PortableServer::POA::ServantAlreadyActive&)
111   {
112     INFOS("Caught CORBA::ServantAlreadyActiveException")
113   }
114   catch(CORBA::Exception&) {
115     INFOS("Caught CORBA::Exception.")
116   }
117   catch(...) {
118     INFOS("Caught unknown exception.")
119    }
120   END_OF(argv[0]);
121   delete myThreadTrace;
122   return 0;
123 }
124