Back to index

salome-kernel  6.5.0
TestMPIContainer.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //=============================================================================
00024 // File      : TestMPIContainer.cxx
00025 // Created   : mer jui 4 13:11:27 CEST 2003
00026 // Author    : Bernard SECHER, 2003
00027 // Project   : SALOME
00028 // $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/TestMPIContainer/TestMPIContainer.cxx,v 1.12.2.1.10.2.12.1 2012-04-12 14:05:32 vsr Exp $
00029 //=============================================================================
00030 //
00031 #include "utilities.h"
00032 #include <iostream>
00033 #include <unistd.h>
00034 #include <string>
00035 #include <SALOMEconfig.h>
00036 #include CORBA_CLIENT_HEADER(SALOME_MPIContainer)
00037 #include CORBA_CLIENT_HEADER(SALOME_TestMPIComponent)
00038 
00039 #include "Basics_Utils.hxx"
00040 # include "Utils_ORB_INIT.hxx"
00041 # include "Utils_SINGLETON.hxx"
00042 #include "SALOME_NamingService.hxx"
00043 #include "OpUtil.hxx"
00044 
00045 int main (int argc, char * argv[])
00046 {
00047 
00048   // Initializing omniORB
00049   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
00050   CORBA::ORB_var &orb = init( argc , argv ) ;
00051   //  SALOMETraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
00052     
00053   BEGIN_OF(argv[0])
00054   try{
00055 
00056     int status;
00057 
00058     if( argc != 3 || strcmp(argv[1],"-np") ){
00059       std::cout << "Usage: TestMPIContainer -np nbproc" << std::endl;
00060       exit(0);
00061     }
00062 
00063     // Obtain a reference to the root POA
00064     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA") ;
00065     PortableServer::POA_var poa = PortableServer::POA::_narrow(obj) ;
00066 
00067     // Use Name Service to find container
00068     SALOME_NamingService NS(orb) ;
00069     std::string containerName = "/Containers/" ;
00070     std::string hostName = Kernel_Utils::GetHostname();
00071     containerName += hostName + "/MPIFactoryServer_" + argv[2];
00072 
00073     std::string dirn(getenv("KERNEL_ROOT_DIR"));
00074     dirn += "/lib/salome/libSalomeTestMPIComponentEngine.so";
00075     
00076     // Try to resolve MPI Container
00077     obj = NS.Resolve(containerName.c_str()) ;
00078     Engines::MPIContainer_var iGenFact = Engines::MPIContainer::_narrow(obj);
00079 
00080     if(CORBA::is_nil(iGenFact)){
00081 
00082       // Launch MPI Container
00083       std::string cmd("mpirun -np ");
00084       cmd += argv[2];
00085       cmd += " ";
00086       cmd += getenv("KERNEL_ROOT_DIR");
00087       cmd += "/bin/salome/SALOME_MPIContainer MPIFactoryServer_";
00088       cmd += argv[2];
00089       cmd += " &";
00090       MESSAGE(cmd);
00091       status = system(cmd.c_str());
00092       if (status == -1) {
00093         INFOS("TestMPIContainer launch MPI Container failed (system command status -1)") ;
00094       }
00095       else if (status == 217) {
00096         INFOS("TestMPIContainer launch MPI Container failed (system command status 217)") ;
00097       }
00098     
00099       // Try to resolve MPI Container
00100       int it = 0;
00101       do{
00102         sleep(1);
00103         obj = NS.Resolve(containerName.c_str()) ;
00104         iGenFact = Engines::MPIContainer::_narrow(obj);
00105         MESSAGE("Waiting for MPI Container " << containerName << " : it = " << it );
00106       }while( CORBA::is_nil(iGenFact) && (it++<15) );
00107 
00108     }
00109 
00110     if(CORBA::is_nil(iGenFact)){
00111       MESSAGE("launching container failed");
00112       exit(1);
00113     }
00114 
00115 
00116     Engines::TestMPIComponent_var m1;
00117 
00118 //     for (int iter = 0; iter < 1 ; iter++){
00119 //       MESSAGE("----------------------------------------------------" << iter);   
00120     obj = iGenFact->load_impl("TestMPIComponent",dirn.c_str());
00121 
00122     INFOS("Get Handle on MPI Component");
00123     m1 = Engines::TestMPIComponent::_narrow(obj);
00124     if(CORBA::is_nil(m1)){
00125       INFOS("getting handle on MPI component failed");
00126     }
00127     else{ 
00128       m1->Coucou(1L);
00129 // //   sleep(5);
00130       INFOS("Unload MPI Component");
00131       iGenFact->remove_impl(m1) ;
00132     }
00133 //     }
00134 //     // Clean-up.
00135 // //     iGenFact->finalize_removal() ;
00136 // //     sleep(5);
00137     iGenFact->Shutdown();
00138 //     INFOS("shut down corba server for Test MPI Container");
00139 //     orb->destroy();
00140   }
00141   catch(CORBA::COMM_FAILURE& ex) {
00142     INFOS("Caught system exception COMM_FAILURE -- unable to contact the object.");
00143   }
00144   catch(CORBA::SystemException&) {
00145     INFOS("Caught a CORBA::SystemException.");
00146   }
00147   catch(CORBA::Exception&) {
00148     INFOS("Caught CORBA::Exception.");
00149   }
00150   catch(...) {
00151     INFOS("Caught unknown exception.");
00152   }
00153 
00154   END_OF(argv[0]);
00155   //  delete myThreadTrace;
00156   return 0 ;
00157 }