1 // Copyright (C) 2007-2019 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, or (at your option) any later version.
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
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"
45 int main (int argc, char * argv[])
48 // Initializing omniORB
49 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
50 CORBA::ORB_var &orb = init( argc , argv ) ;
51 // SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
58 if( argc != 3 || strcmp(argv[1],"-np") ){
59 std::cout << "Usage: TestMPIContainer -np nbproc" << std::endl;
63 // Obtain a reference to the root POA
64 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
65 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
67 // Use Name Service to find container
68 SALOME_NamingService NS(orb) ;
69 std::string containerName = "/Containers/" ;
70 std::string hostName = Kernel_Utils::GetHostname();
71 containerName += hostName + "/MPIFactoryServer_" + argv[2];
73 std::string dirn(getenv("KERNEL_ROOT_DIR"));
75 dirn += "/lib/salome/libSalomeTestMPIComponentEngine.dylib";
77 dirn += "/lib/salome/libSalomeTestMPIComponentEngine.so";
80 // Try to resolve MPI Container
81 obj = NS.Resolve(containerName.c_str()) ;
82 Engines::MPIContainer_var iGenFact = Engines::MPIContainer::_narrow(obj);
84 if(CORBA::is_nil(iGenFact)){
86 // Launch MPI Container
87 std::string cmd("mpirun -np ");
90 cmd += getenv("KERNEL_ROOT_DIR");
91 cmd += "/bin/salome/SALOME_MPIContainer MPIFactoryServer_";
95 status = system(cmd.c_str());
97 INFOS("TestMPIContainer launch MPI Container failed (system command status -1)") ;
99 else if (status == 217) {
100 INFOS("TestMPIContainer launch MPI Container failed (system command status 217)") ;
103 // Try to resolve MPI Container
107 obj = NS.Resolve(containerName.c_str()) ;
108 iGenFact = Engines::MPIContainer::_narrow(obj);
109 MESSAGE("Waiting for MPI Container " << containerName << " : it = " << it );
110 }while( CORBA::is_nil(iGenFact) && (it++<15) );
114 if(CORBA::is_nil(iGenFact)){
115 MESSAGE("launching container failed");
120 Engines::TestMPIComponent_var m1;
122 // for (int iter = 0; iter < 1 ; iter++){
123 // MESSAGE("----------------------------------------------------" << iter);
124 obj = iGenFact->load_impl("TestMPIComponent",dirn.c_str());
126 INFOS("Get Handle on MPI Component");
127 m1 = Engines::TestMPIComponent::_narrow(obj);
128 if(CORBA::is_nil(m1)){
129 INFOS("getting handle on MPI component failed");
133 // Display MPI component in naming service
134 std::string cmdn = "nameclt list Containers.dir/";
137 system(cmdn.c_str());
138 cmdn = "nameclt list Containers.dir/";
140 cmdn += ".dir/MPIFactoryServer_";
143 system(cmdn.c_str());
145 INFOS("Unload MPI Component");
146 iGenFact->remove_impl(m1) ;
150 // // iGenFact->finalize_removal() ;
152 iGenFact->Shutdown();
153 // INFOS("shut down corba server for Test MPI Container");
156 catch(CORBA::COMM_FAILURE& ex) {
157 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
159 catch(CORBA::SystemException&) {
160 INFOS("Caught a CORBA::SystemException.");
162 catch(CORBA::Exception&) {
163 INFOS("Caught CORBA::Exception.");
166 INFOS("Caught unknown exception.");
170 // delete myThreadTrace;