1 // Copyright (C) 2020-2023 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (EDF R&D)
23 #include "ParaDataArray.hxx"
24 #include "CommInterface.hxx"
25 #include "MEDCouplingMemArray.txx"
32 ParaDataArrayTemplate<T>::ParaDataArrayTemplate(typename Traits<T>::ArrayType *seqDa)
34 this->_seq_da.takeRef(seqDa);
38 std::size_t ParaDataArrayTemplate<T>::getHeapMemorySizeWithoutChildren() const
44 std::vector<const BigMemoryObject *> ParaDataArrayTemplate<T>::getDirectChildrenWithNull() const
46 return { this->_seq_da };
50 void ParaDataArrayTemplate<T>::checkOKOneComponent(const std::string& msg) const
52 if(this->_seq_da.isNull())
54 std::ostringstream oss; oss << msg << " : nullptr internal pointer !";
55 throw INTERP_KERNEL::Exception(oss.str());
57 this->_seq_da->checkAllocated();
58 if( this->_seq_da->getNumberOfComponents()!=1 )
60 std::ostringstream oss; oss << msg << " : internal seq dataarray does not contain one component as expected !";
61 throw INTERP_KERNEL::Exception(oss.str());
66 Parallel version of DataArrayInt::buildComplement. Returns result on proc 0. Not allocated DataArrayT is returned for all procs.
69 DataArrayIdType *ParaDataArrayDiscrete<T>::buildComplement(T nbOfElems) const
71 using DataArrayT = typename Traits<T>::ArrayType;
72 this->checkOKOneComponent("ParaDataArray::buildComplement");
73 MPI_Comm comm(MPI_COMM_WORLD);
76 ci.commSize(comm,&size);
77 std::vector< MCAuto<DataArrayT> > idsCaptured(size);
78 for(int curRk = 0 ; curRk < size ; ++curRk)
80 T curStart(0),curEnd(0);
81 DataArrayTools<T>::GetSlice(0,nbOfElems,1,ToIdType(curRk),ToIdType(size),curStart,curEnd);
82 MCAuto<DataArrayIdType> idsInGlobalIds(this->_seq_da->findIdsInRange(curStart,curEnd));
83 idsCaptured[curRk] = this->_seq_da->selectByTupleIdSafe(idsInGlobalIds->begin(),idsInGlobalIds->end());
85 // communication : 1 arrays are going to be all2allized : ids
86 MCAuto<DataArrayT> aggregatedIds;
88 std::vector< MCAuto<DataArrayT> > myRkIdsCaptured;
89 ci.allToAllArraysT<T>(comm,idsCaptured,myRkIdsCaptured);
90 aggregatedIds = DataArrayT::Aggregate(FromVecAutoToVecOfConst<DataArrayT>(myRkIdsCaptured));
92 aggregatedIds->sort();
93 aggregatedIds = aggregatedIds->buildUnique();
95 ci.commRank(comm,&rank);
96 T vmin(std::numeric_limits<T>::max()),vmax(-std::numeric_limits<T>::max());
97 DataArrayTools<T>::GetSlice(0,nbOfElems,1,ToIdType(rank),ToIdType(size),vmin,vmax);
98 aggregatedIds->applyLin(1,-vmin);
99 MCAuto<DataArrayIdType> seqComp(aggregatedIds->buildComplement(ToIdType(vmax-vmin)));
100 seqComp->applyLin(1,ToIdType(vmin));
102 std::vector< MCAuto<DataArrayIdType> > arraysOut;
103 ci.gatherArrays(comm,0,seqComp,arraysOut);
104 MCAuto<DataArrayIdType> ret(DataArrayIdType::Aggregate(FromVecAutoToVecOfConst<DataArrayIdType>(arraysOut)));