1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // using namespace std;
23 //=============================================================================
24 // File : TestMPIContainer.cxx
25 // Created : mer jui 4 13:11:27 CEST 2003
26 // Author : Bernard SECHER, 2003
29 //=============================================================================
31 #include "utilities.h"
35 #include <SALOMEconfig.h>
36 #include CORBA_CLIENT_HEADER(SALOME_MPIContainer)
37 #include CORBA_CLIENT_HEADER(SALOME_TestMPIComponent)
39 #include "Basics_Utils.hxx"
40 # include "Utils_ORB_INIT.hxx"
41 # include "Utils_SINGLETON.hxx"
42 #include "SALOME_NamingService.hxx"
46 int main (int argc, char * argv[])
49 // Initializing omniORB
50 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
51 CORBA::ORB_var &orb = init( argc , argv ) ;
52 // SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
59 if( argc != 3 || strcmp(argv[1],"-np") ){
60 cout << "Usage: TestMPIContainer -np nbproc" << endl;
64 // Obtain a reference to the root POA
65 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
66 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
68 // Use Name Service to find container
69 SALOME_NamingService NS(orb) ;
70 string containerName = "/Containers/" ;
71 string hostName = Kernel_Utils::GetHostname();
72 containerName += hostName + "/MPIFactoryServer_" + argv[2];
74 string dirn(getenv("KERNEL_ROOT_DIR"));
75 dirn += "/lib/salome/libSalomeTestMPIComponentEngine.so";
77 // Try to resolve MPI Container
78 obj = NS.Resolve(containerName.c_str()) ;
79 Engines::MPIContainer_var iGenFact = Engines::MPIContainer::_narrow(obj);
81 if(CORBA::is_nil(iGenFact)){
83 // Launch MPI Container
84 string cmd("mpirun -np ");
87 cmd += getenv("KERNEL_ROOT_DIR");
88 cmd += "/bin/salome/SALOME_MPIContainer MPIFactoryServer_";
92 status = system(cmd.c_str());
94 INFOS("TestMPIContainer launch MPI Container failed (system command status -1)") ;
96 else if (status == 217) {
97 INFOS("TestMPIContainer launch MPI Container failed (system command status 217)") ;
100 // Try to resolve MPI Container
104 obj = NS.Resolve(containerName.c_str()) ;
105 iGenFact = Engines::MPIContainer::_narrow(obj);
106 MESSAGE("Waiting for MPI Container " << containerName << " : it = " << it );
107 }while( CORBA::is_nil(iGenFact) && (it++<15) );
111 if(CORBA::is_nil(iGenFact)){
112 MESSAGE("launching container failed");
117 Engines::TestMPIComponent_var m1;
119 // for (int iter = 0; iter < 1 ; iter++){
120 // MESSAGE("----------------------------------------------------" << iter);
121 obj = iGenFact->load_impl("TestMPIComponent",dirn.c_str());
123 INFOS("Get Handle on MPI Component");
124 m1 = Engines::TestMPIComponent::_narrow(obj);
125 if(CORBA::is_nil(m1)){
126 INFOS("getting handle on MPI component failed");
131 INFOS("Unload MPI Component");
132 iGenFact->remove_impl(m1) ;
136 // // iGenFact->finalize_removal() ;
138 iGenFact->Shutdown();
139 // INFOS("shut down corba server for Test MPI Container");
142 catch(CORBA::COMM_FAILURE& ex) {
143 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
145 catch(CORBA::SystemException&) {
146 INFOS("Caught a CORBA::SystemException.");
148 catch(CORBA::Exception&) {
149 INFOS("Caught CORBA::Exception.");
152 INFOS("Caught unknown exception.");
156 // delete myThreadTrace;