1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/
20 // using namespace std;
21 //=============================================================================
22 // File : TestMPIContainer.cxx
23 // Created : mer jui 4 13:11:27 CEST 2003
24 // Author : Bernard SECHER, 2003
26 // Copyright : CEA 2003
28 //=============================================================================
30 #include "utilities.h"
34 #include <SALOMEconfig.h>
35 #include CORBA_CLIENT_HEADER(SALOME_MPIContainer)
36 #include CORBA_CLIENT_HEADER(SALOME_TestMPIComponent)
38 # include "Utils_ORB_INIT.hxx"
39 # include "Utils_SINGLETON.hxx"
40 #include "SALOME_NamingService.hxx"
42 #include "SALOMETraceCollector.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 cout << "Usage: TestMPIContainer -np nbproc" << 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 string containerName = "/Containers/" ;
70 string hostName = GetHostname();
71 containerName += hostName + "/MPIFactoryServer_" + argv[2];
73 string dirn(getenv("KERNEL_ROOT_DIR"));
74 dirn += "/lib/salome/libSalomeTestMPIComponentEngine.so";
76 // Try to resolve MPI Container
77 obj = NS.Resolve(containerName.c_str()) ;
78 Engines::MPIContainer_var iGenFact = Engines::MPIContainer::_narrow(obj);
80 if(CORBA::is_nil(iGenFact)){
82 // Launch MPI Container
83 string cmd("mpirun -np ");
86 cmd += getenv("KERNEL_ROOT_DIR");
87 cmd += "/bin/salome/SALOME_MPIContainer MPIFactoryServer_";
91 status = system(cmd.c_str());
93 INFOS("TestMPIContainer launch MPI Container failed (system command status -1)") ;
95 else if (status == 217) {
96 INFOS("TestMPIContainer launch MPI Container failed (system command status 217)") ;
99 // Try to resolve MPI Container
103 obj = NS.Resolve(containerName.c_str()) ;
104 iGenFact = Engines::MPIContainer::_narrow(obj);
105 MESSAGE("Waiting for MPI Container " << containerName << " : it = " << it );
106 }while( CORBA::is_nil(iGenFact) && (it++<15) );
110 if(CORBA::is_nil(iGenFact)){
111 MESSAGE("launching container failed");
116 Engines::TestMPIComponent_var m1;
118 // for (int iter = 0; iter < 1 ; iter++){
119 // MESSAGE("----------------------------------------------------" << iter);
120 obj = iGenFact->load_impl("TestMPIComponent",dirn.c_str());
122 INFOS("Get Handle on MPI Component");
123 m1 = Engines::TestMPIComponent::_narrow(obj);
124 if(CORBA::is_nil(m1)){
125 INFOS("getting handle on MPI component failed");
130 INFOS("Unload MPI Component");
131 iGenFact->remove_impl(m1) ;
135 // // iGenFact->finalize_removal() ;
137 iGenFact->Shutdown();
138 // INFOS("shut down corba server for Test MPI Container");
141 catch(CORBA::COMM_FAILURE& ex) {
142 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
144 catch(CORBA::SystemException&) {
145 INFOS("Caught a CORBA::SystemException.");
147 catch(CORBA::Exception&) {
148 INFOS("Caught CORBA::Exception.");
151 INFOS("Caught unknown exception.");
155 // delete myThreadTrace;