Back to index

salome-med  6.5.0
MPIMEDCouplingFieldDoubleServant.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "MPIMEDCouplingFieldDoubleServant.hxx"
00021 #include "utilities.h"
00022 using namespace std;
00023 using namespace ParaMEDMEM;
00024 
00025 typedef struct
00026 {
00027   bool exception;
00028   string msg;
00029 } except_st;
00030 
00031 MPIMEDCouplingFieldDoubleServant::MPIMEDCouplingFieldDoubleServant(CORBA::ORB_ptr orb,PortableServer::POA_ptr poa,ParaMEDMEMComponent_i *pcompo,MEDCouplingFieldDouble* field):ParaMEDCouplingFieldDoubleServant(orb,field)
00032 {
00033   _pcompo = pcompo;
00034   _field = field;
00035 
00036   CORBA::Object_var my_ref = poa->servant_to_reference (pcompo);
00037   SALOME_MED::ParaMEDMEMComponent_var compo = SALOME_MED::ParaMEDMEMComponent::_narrow(my_ref);
00038   _ref = orb->object_to_string(compo);
00039 
00040   Engines::MPIObject_var pobj = POA_SALOME_MED::MPIMEDCouplingFieldDoubleCorbaInterface::_this();
00041   BCastIOR(orb,pobj,false);
00042 }
00043 
00044 void MPIMEDCouplingFieldDoubleServant::getDataByMPI(const char* coupling) throw(SALOME::SALOME_Exception)
00045 {
00046   except_st *est;
00047   void *ret_th;
00048   pthread_t *th;
00049 
00050   if(_numproc == 0)
00051     {
00052       th = new pthread_t[_nbproc];
00053       for(int ip=1;ip<_nbproc;ip++)
00054         {
00055           thread_st *st = new thread_st;
00056           st->ip = ip;
00057           st->tior = _tior;
00058           st->coupling = coupling;
00059           pthread_create(&(th[ip]),NULL,th_getdatabympi,(void*)st);
00060         }
00061     }
00062 
00063   try
00064     {
00065       _pcompo->_getOutputField(coupling,_field);
00066     }
00067   catch(const std::exception &ex)
00068     {
00069       MESSAGE(ex.what());
00070       THROW_SALOME_CORBA_EXCEPTION(ex.what(),SALOME::INTERNAL_ERROR);
00071     }
00072     
00073   if(_numproc == 0)
00074     {
00075       for(int ip=1;ip<_nbproc;ip++)
00076         {
00077           pthread_join(th[ip],&ret_th);
00078           est = (except_st*)ret_th;
00079           if(est->exception)
00080             {
00081               ostringstream msg;
00082               msg << "[" << ip << "] " << est->msg;
00083               THROW_SALOME_CORBA_EXCEPTION(msg.str().c_str(),SALOME::INTERNAL_ERROR);
00084             }
00085           delete est;
00086         }
00087       delete[] th;
00088     }
00089 }
00090 
00091 void *th_getdatabympi(void *s)
00092 {
00093   ostringstream msg;
00094   thread_st *st = (thread_st*)s;
00095   except_st *est = new except_st;
00096   est->exception = false;
00097 
00098   try
00099     {
00100       SALOME_MED::MPIMEDCouplingFieldDoubleCorbaInterface_var fieldPtr=SALOME_MED::MPIMEDCouplingFieldDoubleCorbaInterface::_narrow((*(st->tior))[st->ip]);
00101       fieldPtr->getDataByMPI(st->coupling.c_str());
00102     }
00103   catch(const SALOME::SALOME_Exception &ex)
00104     {
00105       est->exception = true;
00106       est->msg = ex.details.text;
00107     }
00108   catch(const CORBA::Exception &ex)
00109     {
00110       est->exception = true;
00111       msg << "CORBA::Exception: " << ex;
00112       est->msg = msg.str();
00113     }
00114   delete st;
00115   return((void*)est);
00116 }
00117 
00118 char *MPIMEDCouplingFieldDoubleServant::getRef()
00119 {
00120   return CORBA::string_dup(_ref.c_str());
00121 }
00122