1 // Copyright (C) 2007-2008 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.
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
22 // SALOME ParallelContainerProxyMpi : Launching the proxy of a MPI PaCO++ object
23 // File : SALOME_ParallelContainerProxyMpi.cxx
24 // Author : André Ribes, EDF
25 // Module : SALOME PARALLEL
37 //#include "SALOME_ComponentPaCO_Engines_Container_server.h"
38 #include "SALOME_ParallelContainerProxy_i.hxx"
39 #include <paco_omni.h>
40 #include <paco_dummy.h>
44 #include "SALOME_NamingService.hxx"
46 #include "utilities.h"
47 #include "Basics_Utils.hxx"
48 #include "Utils_ORB_INIT.hxx"
49 #include "Utils_SINGLETON.hxx"
50 #include "SALOMETraceCollector.hxx"
53 #include "Container_init_python.hxx"
59 typedef void (*sighandler_t)(int);
60 sighandler_t setsig(int sig, sighandler_t handler)
62 struct sigaction context, ocontext;
63 context.sa_handler = handler;
64 sigemptyset(&context.sa_mask);
66 if (sigaction(sig, &context, &ocontext) == -1)
68 return ocontext.sa_handler;
73 if(getenv ("DEBUGGER"))
75 std::stringstream exec;
76 exec << "$DEBUGGER SALOME_ParallelContainerProxyMpi " << getpid() << "&";
77 std::cerr << exec.str() << std::endl;
78 system(exec.str().c_str());
83 void Handler(int theSigId)
85 std::cerr << "SIGSEGV: " << std::endl;
87 //to exit or not to exit
91 void terminateHandler(void)
93 std::cerr << "Terminate: not managed exception !" << std::endl;
97 void unexpectedHandler(void)
99 std::cerr << "Unexpected: unexpected exception !" << std::endl;
103 void handler(int t) {
104 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
105 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
106 cerr << "SIGSEGV in :" << getpid() << endl;
107 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
108 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
113 int main(int argc, char* argv[])
115 INFOS("Launching a parallel Mpi proxy container");
118 signal(SIGSEGV, handler);
123 MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED ,&provided);
124 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
125 KERNEL_PYTHON::init_python(argc,argv);
128 if(getenv ("DEBUGGER"))
130 std::cerr << "Unexpected: unexpected exception !" << std::endl;
131 setsig(SIGSEGV,&Handler);
132 //set_terminate(&terminateHandler);
133 set_terminate(__gnu_cxx::__verbose_terminate_handler);
134 set_unexpected(&unexpectedHandler);
138 std::string containerName("");
139 containerName = argv[1];
141 sscanf(argv[2],"%d",&nb_nodes);
144 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
145 ASSERT(!CORBA::is_nil(obj));
146 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
147 PortableServer::POAManager_var pman = root_poa->the_POAManager();
150 // add this container to the kill list
152 sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerProxyMpi", getpid());
156 SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
159 paco_fabrique_manager* pfm = paco_getFabriqueManager();
160 pfm->register_com("dummy", new paco_dummy_fabrique());
161 pfm->register_thread("omnithread", new paco_omni_fabrique());
163 Container_proxy_impl_final * proxy = new Container_proxy_impl_final(orb,
164 pfm->get_thread("omnithread"),
169 proxy->setLibCom("dummy", proxy);
170 proxy->setLibThread("omnithread");
171 PaCO::PacoTopology_t serveur_topo;
172 serveur_topo.total = nb_nodes;
173 proxy->setTopology(serveur_topo);
176 //PortableServer::ObjectId_var _id = root_poa->activate_object(proxy);
177 //obj = root_poa->id_to_reference(_id);
178 obj = proxy->_this();
180 // in the NamingService
181 string hostname = Kernel_Utils::GetHostname();
182 Engines::Container_var pCont = Engines::Container::_narrow(obj);
183 string _containerName = ns->BuildContainerNameForNS(containerName.c_str(),
185 cerr << "---------" << _containerName << "----------" << endl;
186 ns->Register(pCont, _containerName.c_str());
190 //Delete python container that destroy orb from python (pyCont._orb.destroy())
195 catch (PaCO::PACO_Exception& e)
197 INFOS("Caught PaCO::PACO_Exception");
198 std::cerr << e << std::endl;
200 catch(CORBA::SystemException&)
202 INFOS("Caught CORBA::SystemException.");
204 catch(PortableServer::POA::ServantAlreadyActive&)
206 INFOS("Caught CORBA::ServantAlreadyActiveException");
208 catch(CORBA::Exception&)
210 INFOS("Caught CORBA::Exception.");
212 catch(std::exception& exc)
214 INFOS("Caught std::exception - "<<exc.what());
218 INFOS("Caught unknown exception.");