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 ParallelContainerNodeMpi : Launch mpi PaCO++ object nodes
23 // File : SALOME_ParallelContainerNodeMpi.cxx
24 // Author : André Ribes, EDF
25 // Module : SALOME PARALLEL
37 #include "SALOME_ParallelContainer_i.hxx"
40 #include <paco_omni.h>
45 #include "SALOME_NamingService.hxx"
47 #include "utilities.h"
48 #include "Utils_ORB_INIT.hxx"
49 #include "Utils_SINGLETON.hxx"
50 #include "SALOMETraceCollector.hxx"
58 void test(int sigval) {
59 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
60 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
61 cerr << "SIGSEGV in :" << getpid() << endl;
62 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
63 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
68 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
69 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
70 cerr << "SIGSEGV in :" << getpid() << endl;
71 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
72 cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
77 typedef void (*sighandler_t)(int);
78 sighandler_t setsig(int sig, sighandler_t handler)
80 struct sigaction context, ocontext;
81 context.sa_handler = handler;
82 sigemptyset(&context.sa_mask);
84 if (sigaction(sig, &context, &ocontext) == -1)
86 return ocontext.sa_handler;
91 if(getenv ("DEBUGGER"))
93 std::stringstream exec;
94 exec << "$DEBUGGER SALOME_ParallelContainerNodeMpi " << getpid() << "&";
95 std::cerr << exec.str() << std::endl;
96 system(exec.str().c_str());
101 void Handler(int theSigId)
103 std::cerr << "SIGSEGV: " << std::endl;
105 //to exit or not to exit
109 void terminateHandler(void)
111 std::cerr << "Terminate: not managed exception !" << std::endl;
115 void unexpectedHandler(void)
117 std::cerr << "Unexpected: unexpected exception !" << std::endl;
121 int main(int argc, char* argv[])
123 INFOS("Launching a parallel Mpi container node");
128 MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE ,&provided);
129 MPI_Comm_rank(MPI_COMM_WORLD,&myid);
131 if(getenv ("DEBUGGER"))
133 std::cerr << "Unexpected: unexpected exception !" << std::endl;
134 setsig(SIGSEGV,&Handler);
135 set_terminate(&terminateHandler);
136 set_unexpected(&unexpectedHandler);
138 cerr << "Level MPI_THREAD_SINGLE : " << MPI_THREAD_SINGLE << endl;
139 cerr << "Level MPI_THREAD_SERIALIZED : " << MPI_THREAD_SERIALIZED << endl;
140 cerr << "Level MPI_THREAD_FUNNELED : " << MPI_THREAD_FUNNELED << endl;
141 cerr << "Level MPI_THREAD_MULTIPLE : " << MPI_THREAD_MULTIPLE << endl;
142 cerr << "Level provided : " << provided << endl;
143 // Initialise the ORB.
144 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
146 // Code pour choisir le reseau infiniband .....
147 /* string hostname_temp = GetHostname();
148 hostent * t = gethostbyname(hostname_temp.c_str());
149 cerr << " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << t->h_addr << " " << hostname_temp << endl;
150 cerr << t->h_addr << endl;
151 in_addr * address=(in_addr * ) t->h_addr;
152 cerr << inet_ntoa(* address) << endl;
153 string ip = inet_ntoa(* address);
154 cerr << " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " << endl;
155 string com = "giop:tcp:" + ip + ":";
156 const char* options[][2] = { { "endPoint", com.c_str() }, { 0, 0 } };
157 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "omniORB4", options);
159 std::string containerName("");
160 containerName = argv[1];
162 std::string hostname("");
168 CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
169 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
170 PortableServer::POAManager_var pman = root_poa->the_POAManager();
173 // add this container to the kill list
175 sprintf(aCommand, "addToKillList.py %d SALOME_ParallelContainerNodeMpi", getpid());
179 SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
180 // On récupère le proxy
181 string proxyNameInNS = ns->BuildContainerNameForNS(containerName.c_str(),
183 obj = ns->Resolve(proxyNameInNS.c_str());
184 char * proxy_ior = orb->object_to_string(obj);
187 string node_name = containerName + "Node";
188 Engines_Parallel_Container_i * servant =
189 new Engines_Parallel_Container_i(CORBA::ORB::_duplicate(orb),
193 (char*) node_name.c_str(),
196 paco_fabrique_manager * pfm = paco_getFabriqueManager();
197 pfm->register_com("mpi", new paco_mpi_fabrique());
198 pfm->register_thread("omni", new paco_omni_fabrique());
199 MPI_Comm group = MPI_COMM_WORLD;
200 servant->setLibCom("mpi", &group);
201 servant->setLibThread("omni");
204 PortableServer::ObjectId * _id = root_poa->activate_object(servant);
205 servant->set_id(_id);
206 obj = root_poa->id_to_reference(*_id);
208 // In the NamingService
209 string hostname = Kernel_Utils::GetHostname();
212 MPI_Comm_rank(MPI_COMM_WORLD, &myid);
214 snprintf(buffer, 5, "%d", myid);
215 node_name = node_name + buffer;
216 string _containerName = ns->BuildContainerNameForNS(node_name.c_str(),
218 cerr << "---------" << _containerName << "----------" << endl;
219 ns->Register(obj, _containerName.c_str());
223 catch (PaCO::PACO_Exception& e)
225 INFOS("Caught PaCO::PACO_Exception");
226 std::cerr << e << std::endl;
228 catch(CORBA::SystemException&)
230 INFOS("Caught CORBA::SystemException.");
232 catch(PortableServer::POA::ServantAlreadyActive&)
234 INFOS("Caught CORBA::ServantAlreadyActiveException");
236 catch(CORBA::Exception&)
238 INFOS("Caught CORBA::Exception.");
240 catch(std::exception& exc)
242 INFOS("Caught std::exception - "<<exc.what());
246 INFOS("Caught unknown exception.");