1 // using namespace std;
2 //=============================================================================
3 // File : TestMPIContainer.cxx
4 // Created : mer jui 4 13:11:27 CEST 2003
5 // Author : Bernard SECHER, 2003
7 // Copyright : CEA 2003
9 //=============================================================================
11 #include "utilities.h"
15 #include <SALOMEconfig.h>
16 #include CORBA_CLIENT_HEADER(SALOME_MPIContainer)
17 #include CORBA_CLIENT_HEADER(SALOME_TestMPIComponent)
19 # include "Utils_ORB_INIT.hxx"
20 # include "Utils_SINGLETON.hxx"
21 #include "SALOME_NamingService.hxx"
24 int main (int argc, char * argv[])
32 if( argc != 3 || strcmp(argv[1],"-np") ){
33 cout << "Usage: TestMPIContainer -np nbproc" << endl;
37 // Initializing omniORB
38 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
40 // Obtain a reference to the root POA
41 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
42 PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
44 // Use Name Service to find container
45 SALOME_NamingService NS(orb) ;
46 string containerName = "/Containers/" ;
47 string hostName = GetHostname();
48 containerName += hostName + "/MPIFactoryServer_" + argv[2];
50 MESSAGE(containerName);
52 string dirn(getenv("KERNEL_ROOT_DIR"));
53 dirn += "/lib/salome/libSalomeTestMPIComponentEngine.so";
54 MESSAGE(dirn.c_str());
56 // Try to resolve MPI Container
57 obj = NS.Resolve(containerName.c_str()) ;
58 Engines::Container_var iGenFact = Engines::Container::_narrow(obj);
60 if(CORBA::is_nil(iGenFact)){
62 // Launch MPI Container
63 string cmd("mpirun -np ");
66 cmd += getenv("KERNEL_ROOT_DIR");
67 cmd += "/bin/salome/SALOME_MPIContainer MPIFactoryServer_";
71 status = system(cmd.c_str());
73 INFOS("TestMPIContainer launch MPI Container failed (system command status -1)") ;
75 else if (status == 217) {
76 INFOS("TestMPIContainer launch MPI Container failed (system command status 217)") ;
79 // Try to resolve MPI Container
83 obj = NS.Resolve(containerName.c_str()) ;
84 iGenFact = Engines::Container::_narrow(obj);
85 MESSAGE("Waiting for MPI Container " << containerName << " : it = " << it );
86 }while( CORBA::is_nil(iGenFact) && (it++<15) );
90 if(CORBA::is_nil(iGenFact)){
91 MESSAGE("echec recuperation poignee container");
95 Engines::TestMPIComponent_var m1;
97 for (int iter = 0; iter < 1 ; iter++){
98 MESSAGE("----------------------------------------------------" << iter);
99 obj = iGenFact->load_impl("TestMPIComponent",dirn.c_str());
101 m1 = Engines::TestMPIComponent::_narrow(obj);
102 if(CORBA::is_nil(m1)){
103 INFOS("echec recuperation poignee composant");
108 SCRUTE(m1->instanceName());
109 INFOS("Lancement de coucou");
111 INFOS("On remove le composant");
112 iGenFact->remove_impl(m1) ;
117 iGenFact->finalize_removal() ;
120 catch(CORBA::COMM_FAILURE& ex) {
121 INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
123 catch(CORBA::SystemException&) {
124 INFOS("Caught a CORBA::SystemException.");
126 catch(CORBA::Exception&) {
127 INFOS("Caught CORBA::Exception.");
130 INFOS("Caught unknown exception.");