1 // Copyright (C) 2007-2020 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 // SALOME ParallelContainerProxyMpi : Launching the proxy of a MPI PaCO++ object
24 // File : SALOME_ParallelContainerProxyMpi.cxx
25 // Author : André Ribes, EDF
26 // Module : SALOME PARALLEL
38 //#include "SALOME_ComponentPaCO_Engines_Container_server.h"
39 #include "SALOME_ParallelContainerProxy_i.hxx"
40 #include <paco_omni.h>
41 #include <paco_dummy.h>
45 #include "SALOME_NamingService.hxx"
47 #include "utilities.h"
48 #include "Basics_Utils.hxx"
49 #include "Utils_ORB_INIT.hxx"
50 #include "Utils_SINGLETON.hxx"
51 #include "SALOMETraceCollector.hxx"
54 #include "Container_init_python.hxx"
60 typedef void (*sighandler_t)(int);
61 sighandler_t setsig(int sig, sighandler_t handler)
63 struct sigaction context, ocontext;
64 context.sa_handler = handler;
65 sigemptyset(&context.sa_mask);
67 if (sigaction(sig, &context, &ocontext) == -1)
69 return ocontext.sa_handler;
74 if(getenv ("DEBUGGER"))
76 std::stringstream exec;
77 exec << "$DEBUGGER SALOME_ParallelContainerProxyMpi " << getpid() << "&";
78 std::cerr << exec.str() << std::endl;
79 system(exec.str().c_str());
84 void Handler(int theSigId)
86 std::cerr << "SIGSEGV: " << std::endl;
88 //to exit or not to exit
92 void terminateHandler(void)
94 std::cerr << "Terminate: not managed exception !" << std::endl;
98 void unexpectedHandler(void)
100 std::cerr << "Unexpected: unexpected exception !" << std::endl;
104 void handler(int t) {
105 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
106 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
107 std::cerr << "SIGSEGV in :" << getpid() << std::endl;
108 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
109 std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
114 int main(int argc, char* argv[])
116 INFOS("Launching a parallel Mpi proxy container");
119 signal(SIGSEGV, handler);
124 MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED ,&provided);
125 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
126 KERNEL_PYTHON::init_python(argc,argv);
129 if(getenv ("DEBUGGER"))
131 std::cerr << "Unexpected: unexpected exception !" << std::endl;
132 setsig(SIGSEGV,&Handler);
133 //set_terminate(&terminateHandler);
134 set_terminate(__gnu_cxx::__verbose_terminate_handler);
135 set_unexpected(&unexpectedHandler);
139 std::string containerName("");
140 containerName = argv[1];
142 sscanf(argv[2],"%d",&nb_nodes);
145 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
146 ASSERT(!CORBA::is_nil(obj));
147 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
148 PortableServer::POAManager_var pman = root_poa->the_POAManager();
151 // add this container to the kill list
153 sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerProxyMpi", getpid());
157 SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
160 paco_fabrique_manager* pfm = paco_getFabriqueManager();
161 pfm->register_com("dummy", new paco_dummy_fabrique());
162 pfm->register_thread("omnithread", new paco_omni_fabrique());
164 Container_proxy_impl_final * proxy = new Container_proxy_impl_final(orb,
165 pfm->get_thread("omnithread"),
170 proxy->setLibCom("dummy", proxy);
171 proxy->setLibThread("omnithread");
172 PaCO::PacoTopology_t serveur_topo;
173 serveur_topo.total = nb_nodes;
174 proxy->setTopology(serveur_topo);
177 //PortableServer::ObjectId_var _id = root_poa->activate_object(proxy);
178 //obj = root_poa->id_to_reference(_id);
179 obj = proxy->_this();
181 // in the NamingService
182 std::string hostname = Kernel_Utils::GetHostname();
183 Engines::Container_var pCont = Engines::Container::_narrow(obj);
184 std::string _containerName = ns->BuildContainerNameForNS(containerName.c_str(),
186 std::cerr << "---------" << _containerName << "----------" << std::endl;
187 ns->Register(pCont, _containerName.c_str());
191 //Delete python container that destroy orb from python (pyCont._orb.destroy())
196 catch (PaCO::PACO_Exception& e)
198 INFOS("Caught PaCO::PACO_Exception");
199 std::cerr << e << std::endl;
201 catch(CORBA::SystemException&)
203 INFOS("Caught CORBA::SystemException.");
205 catch(PortableServer::POA::ServantAlreadyActive&)
207 INFOS("Caught CORBA::ServantAlreadyActiveException");
209 catch(CORBA::Exception&)
211 INFOS("Caught CORBA::Exception.");
213 catch(std::exception& exc)
215 INFOS("Caught std::exception - "<<exc.what());
219 INFOS("Caught unknown exception.");