X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParaMEDMEM%2FMPIProcessorGroup.cxx;h=055cc5122c8608a2244eafcd13a6ca632fff28e9;hb=a843e859241baea9b4942877174422d2891206ef;hp=fc3f0188a949c5c4022fa190fbbd87fc744573ce;hpb=48782c06022ca2caa36f849cb5a29ea4fe2aaa83;p=tools%2Fmedcoupling.git diff --git a/src/ParaMEDMEM/MPIProcessorGroup.cxx b/src/ParaMEDMEM/MPIProcessorGroup.cxx index fc3f0188a..055cc5122 100644 --- a/src/ParaMEDMEM/MPIProcessorGroup.cxx +++ b/src/ParaMEDMEM/MPIProcessorGroup.cxx @@ -1,21 +1,22 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D +// Copyright (C) 2007-2015 CEA/DEN, EDF R&D // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + #include "ProcessorGroup.hxx" #include "MPIProcessorGroup.hxx" #include "CommInterface.hxx" @@ -87,6 +88,12 @@ namespace ParaMEDMEM MPIProcessorGroup::MPIProcessorGroup(const CommInterface& interface, set proc_ids, const MPI_Comm& world_comm): ProcessorGroup(interface, proc_ids),_world_comm(world_comm) + { + updateMPISpecificAttributes(); + } + + + void MPIProcessorGroup::updateMPISpecificAttributes() { //Creation of a communicator MPI_Group group_world; @@ -97,19 +104,27 @@ namespace ParaMEDMEM _comm_interface.commRank(_world_comm,&rank_world); _comm_interface.commGroup(_world_comm, &group_world); - int* ranks=new int[proc_ids.size()]; + int* ranks=new int[_proc_ids.size()]; // copying proc_ids in ranks - copy::const_iterator,int*> (proc_ids.begin(), proc_ids.end(), ranks); - for (int i=0; i< proc_ids.size();i++) + copy::const_iterator,int*> (_proc_ids.begin(), _proc_ids.end(), ranks); + for (int i=0; i< (int)_proc_ids.size();i++) if (ranks[i]>size_world-1) - throw INTERP_KERNEL::Exception("invalid rank in set argument of MPIProcessorGroup constructor"); + { + delete[] ranks; + _comm_interface.groupFree(&group_world); // MPI_Group is a C structure and won't get de-allocated automatically? + throw INTERP_KERNEL::Exception("invalid rank in set argument of MPIProcessorGroup constructor"); + } - _comm_interface.groupIncl(group_world, proc_ids.size(), ranks, &_group); + _comm_interface.groupIncl(group_world, _proc_ids.size(), ranks, &_group); _comm_interface.commCreate(_world_comm, _group, &_comm); + + // clean-up delete[] ranks; + _comm_interface.groupFree(&group_world); // MPI_Group is a C structure and won't get de-allocated automatically? } + /*! Creates a processor group that is based on the processors between \a pstart and \a pend. This routine must be called by all processors in MPI_COMM_WORLD. @@ -118,7 +133,7 @@ namespace ParaMEDMEM \param pstart id in MPI_COMM_WORLD of the first processor in the group \param pend id in MPI_COMM_WORLD of the last processor in the group */ - MPIProcessorGroup::MPIProcessorGroup (const CommInterface& comm_interface, int pstart, int pend): ProcessorGroup(comm_interface,pstart,pend),_world_comm(MPI_COMM_WORLD) + MPIProcessorGroup::MPIProcessorGroup (const CommInterface& comm_interface, int pstart, int pend, const MPI_Comm& world_comm): ProcessorGroup(comm_interface,pstart,pend),_world_comm(world_comm) { //Creation of a communicator MPI_Group group_world; @@ -130,7 +145,10 @@ namespace ParaMEDMEM _comm_interface.commGroup(_world_comm, &group_world); if (pend>size_world-1 || pend ::const_iterator iter=_proc_ids.begin(); iter!= _proc_ids.end(); iter++) procs.insert(*iter); - return new MPIProcessorGroup(_comm_interface, procs); + return new MPIProcessorGroup(_comm_interface, procs, _world_comm); } }