From: vbd Date: Tue, 13 Feb 2007 15:06:56 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: trio_trio_coupling~107 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c7135acee13fde47eb5da1f186db3df3c6220645;p=tools%2Fmedcoupling.git *** empty log message *** --- diff --git a/src/ParaMEDMEM/CommInterface.hxx b/src/ParaMEDMEM/CommInterface.hxx index 6972b54ee..1c4c3c822 100644 --- a/src/ParaMEDMEM/CommInterface.hxx +++ b/src/ParaMEDMEM/CommInterface.hxx @@ -32,12 +32,19 @@ public: {return MPI_Alltoallv(sendbuf, sendcounts, senddispls, sendtype, recvbuf, recvcounts, recvdispls, recvtype, comm);} + int allToAll(void* sendbuf, int sendcount, MPI_Datatype sendtype, + void* recvbuf, int recvcount, MPI_Datatype recvtype, + MPI_Comm comm) const + { + return MPI_Alltoall(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm); + } int allGather(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm) const {return MPI_Allgather(sendbuf,sendcount, sendtype, recvbuf, recvcount, recvtype, comm); } - + + int worldSize() const {int size; MPI_Comm_size(MPI_COMM_WORLD, &size); return size;} }; } diff --git a/src/ParaMEDMEM/DEC.cxx b/src/ParaMEDMEM/DEC.cxx index 773e2618c..27c93d0b0 100644 --- a/src/ParaMEDMEM/DEC.cxx +++ b/src/ParaMEDMEM/DEC.cxx @@ -15,18 +15,18 @@ namespace ParaMEDMEM void DEC::attachTargetField(const ParaFIELD* field) { _target_field=field; - if (field!=0) - { - BlockTopology* topo=dynamic_cast(field->getTopology()); - _comm_interface=&(topo->getProcGroup()->getCommInterface()); - } + //if (field!=0) + //{ + //BlockTopology* topo=dynamic_cast(field->getTopology()); + _comm_interface=&(field->getTopology()->getProcGroup()->getCommInterface()); + //} } void DEC::attachSourceField(const ParaFIELD* field) {_source_field=field; - if (field!=0) - { - BlockTopology* topo=dynamic_cast(field->getTopology()); - _comm_interface=&(topo->getProcGroup()->getCommInterface()); - } +//if (field!=0) +//{ +// BlockTopology* topo=dynamic_cast(field->getTopology()); + _comm_interface=&(field->getTopology()->getProcGroup()->getCommInterface()); + //} } } diff --git a/src/ParaMEDMEM/ExplicitCoincidentDEC.cxx b/src/ParaMEDMEM/ExplicitCoincidentDEC.cxx index aa9309029..e9ca495ef 100644 --- a/src/ParaMEDMEM/ExplicitCoincidentDEC.cxx +++ b/src/ParaMEDMEM/ExplicitCoincidentDEC.cxx @@ -6,6 +6,8 @@ #include "ParaFIELD.hxx" #include "MPIProcessorGroup.hxx" #include "ExplicitCoincidentDEC.hxx" +#include "ExplicitMapping.hxx" + namespace ParaMEDMEM { @@ -22,16 +24,28 @@ ExplicitCoincidentDEC::~ExplicitCoincidentDEC() */ void ExplicitCoincidentDEC::synchronize() { - if (_source_field!=0) - _toposource = dynamic_cast(_source_field->getTopology()); - if (_target_field!=0) - _topotarget = dynamic_cast(_target_field->getTopology()); - - // Transmitting source topology to target code - broadcastTopology(*_toposource,*_topotarget,1000); - // Transmitting target topology to source code - //broadcastTopology(_topotarget,2000); - //checkCompatibility(_toposource,_topotarget); + if (_source_field!=0) + { + _toposource = dynamic_cast(_source_field->getTopology()); + _sourcegroup= _toposource->getProcGroup()->createProcGroup(); + _targetgroup=_toposource->getProcGroup()->createComplementProcGroup(); + } + if (_target_field!=0) + { + _topotarget = dynamic_cast(_target_field->getTopology()); + _sourcegroup= _topotarget->getProcGroup()->createComplementProcGroup(); + _targetgroup=_topotarget->getProcGroup()->createProcGroup(); + } + + // Exchanging + + // Transmitting source topology to target code + broadcastTopology(_toposource,_topotarget,1000); + + transferMappingToSource(); + // Transmitting target topology to source code + // broadcastTopology(_topotarget,_toposource,2000); + //checkCompatibility(_toposource,_topotarget); } /*! Creates the arrays necessary for the data transfer @@ -40,76 +54,73 @@ void ExplicitCoincidentDEC::synchronize() * */ void ExplicitCoincidentDEC::prepareSourceDE() { - //////////////////////////////////// - //Step 1 : buffer array creation - - if (!_toposource->getProcGroup()->containsMyRank()) - return; - MPIProcessorGroup* group=new MPIProcessorGroup(_toposource->getProcGroup()->getCommInterface()); - - int myranksource = _toposource->getProcGroup()->myRank(); - - vector * target_arrays=new vector[_topotarget->getProcGroup()->size()]; - - //cout<<" topotarget size"<< _topotarget->getProcGroup()->size()< getNbLocalElements(); - for (int ielem=0; ielem< nb_local ; ielem++) - { - pair target_local =_distant_elems[ielem]; - target_arrays[target_local.first].push_back(target_local.second); - } - - int union_size=group->size(); - - _sendcounts=new int[union_size]; - _senddispls=new int[union_size]; - _recvcounts=new int[union_size]; - _recvdispls=new int[union_size]; - - for (int i=0; i< union_size; i++) - { - _sendcounts[i]=0; - _recvcounts[i]=0; - _recvdispls[i]=0; - } - _senddispls[0]=0; - - for (int iproc=0; iproc < _topotarget->getProcGroup()->size(); iproc++) - { - //converts the rank in target to the rank in union communicator - int unionrank=group->translateRank(_topotarget->getProcGroup(),iproc); - _sendcounts[unionrank]=target_arrays[iproc].size(); - } - - for (int iproc=1; iprocsize();iproc++) - _senddispls[iproc]=_senddispls[iproc-1]+_sendcounts[iproc-1]; - - _sendbuffer = new double [nb_local ]; - - ///////////////////////////////////////////////////////////// - //Step 2 : filling the buffers with the source field values + //////////////////////////////////// + //Step 1 : buffer array creation + + if (!_toposource->getProcGroup()->containsMyRank()) + return; + MPIProcessorGroup* group=new MPIProcessorGroup(_sourcegroup->getCommInterface()); + + int myranksource = _sourcegroup->myRank(); + + // Warning : the size of the target side is implicitly deduced + //from the size of MPI_COMM_WORLD + int target_size = _toposource->getProcGroup()->getCommInterface().worldSize()- _toposource->getProcGroup()->size() ; + // vector * target_arrays=new vector[_topotarget->getProcGroup()->size()]; + + vector * target_arrays=new vector[target_size]; + //cout<<" topotarget size"<< _topotarget->getProcGroup()->size()< getNbLocalElements(); - int* counter=new int [_topotarget->getProcGroup()->size()]; - counter[0]=0; - for (int i=1; i<_topotarget->getProcGroup()->size(); i++) - counter[i]=counter[i-1]+target_arrays[i-1].size(); - - - const double* value = _source_field->getField()->getValue(); - //cout << "Nb local " << nb_local<size(); + + _sendcounts=new int[union_size]; + _senddispls=new int[union_size]; + _recvcounts=new int[union_size]; + _recvdispls=new int[union_size]; + + for (int i=0; i< union_size; i++) + { + _sendcounts[i]=0; + _recvcounts[i]=0; + _recvdispls[i]=0; + } + _senddispls[0]=0; + + int* counts=_explicit_mapping.getCounts(); + for (int i=0; isize(); i++) + _sendcounts[i]=counts[i]; + + for (int iproc=1; iprocsize();iproc++) + _senddispls[iproc]=_senddispls[iproc-1]+_sendcounts[iproc-1]; + + _sendbuffer = new double [nb_local * _toposource->getNbComponents()]; + + ///////////////////////////////////////////////////////////// + //Step 2 : filling the buffers with the source field values + + int* counter=new int [target_size]; + counter[0]=0; + for (int i=1; igetField()->getValue(); + + int* bufferindex= _explicit_mapping.getBufferIndex(); + + for (int ielem=0; ielemgetNbComponents(); + for (int icomp=0; icomplocalToGlobal(make_pair(myranksource, ielem)); - //int global=_toposource->localToGlobal(ielem); - int target_local =_topotarget->globalToLocal(global); - //cout <<"global : "<< global<<" local :"<getProcGroup()->containsMyRank()) return; - MPIProcessorGroup* group=new MPIProcessorGroup(_toposource->getProcGroup()->getCommInterface()); + MPIProcessorGroup* group=new MPIProcessorGroup(_topotarget->getProcGroup()->getCommInterface()); //int myranktarget = _topotarget->getProcGroup()->myRank(); - vector < vector > source_arrays(_toposource->getProcGroup()->size()); + vector < vector > source_arrays(_sourcegroup->size()); int nb_local = _topotarget-> getNbLocalElements(); for (int ielem=0; ielem< nb_local ; ielem++) { - pair source_local =_distant_elems[ielem]; + //pair source_local =_distant_elems[ielem]; + pair source_local=_explicit_mapping.getDistantNumbering(ielem); source_arrays[source_local.first].push_back(source_local.second); } int union_size=group->size(); @@ -142,15 +154,15 @@ void ExplicitCoincidentDEC::prepareTargetDE() _recvcounts[i]=0; _recvdispls[i]=0; } - for (int iproc=0; iproc < _toposource->getProcGroup()->size(); iproc++) + for (int iproc=0; iproc < _sourcegroup->size(); iproc++) { //converts the rank in target to the rank in union communicator - int unionrank=group->translateRank(_toposource->getProcGroup(),iproc); - _recvcounts[unionrank]=source_arrays[iproc].size(); + int unionrank=group->translateRank(_sourcegroup,iproc); + _recvcounts[unionrank]=source_arrays[iproc].size()*_topotarget->getNbComponents(); } for (int i=1; igetNbComponents()]; } @@ -162,7 +174,7 @@ void ExplicitCoincidentDEC::prepareTargetDE() * \param topo Topology that is transmitted. It is read on processes where it already exists, and it is created and filled on others. * \param tag Communication tag associated with this operation. */ -void ExplicitCoincidentDEC::broadcastTopology(const ExplicitTopology& toposend, ExplicitTopology& toporecv, int tag) +void ExplicitCoincidentDEC::broadcastTopology(const ExplicitTopology* toposend, ExplicitTopology* toporecv, int tag) { MPI_Status status; @@ -173,46 +185,50 @@ void ExplicitCoincidentDEC::broadcastTopology(const ExplicitTopology& toposend, // The send processors serialize the send topology // and send the buffers to the recv procs - if (toposend.getProcGroup()->containsMyRank()) + if (toposend !=0 && toposend->getProcGroup()->containsMyRank()) { - toposend.serialize(serializer, size); + toposend->serialize(serializer, size); for (int iproc=0; iproc< group->size(); iproc++) { - int itarget=(iproc+toposend.getProcGroup()->myRank())%group->size(); - if (!toposend.getProcGroup()->contains(itarget)) + // int itarget=(iproc+toposend->getProcGroup()->myRank())%group->size(); + int itarget=iproc; + if (!toposend->getProcGroup()->contains(itarget)) { - int nbelem = toposend.getNbLocalElements(); - _comm_interface->send(&nbelem,1,MPI_INTEGER, itarget,tag+itarget,*(group->getComm())); - _comm_interface->send(&serializer, size, MPI_INTEGER, itarget, tag+itarget,*(group->getComm())); + // int nbelem = toposend->getNbLocalElements(); + _comm_interface->send(&size,1,MPI_INTEGER, itarget,tag+itarget,*(group->getComm())); + _comm_interface->send(serializer, size, MPI_INTEGER, itarget, tag+itarget,*(group->getComm())); } } } else { vector size (group->size()); - int myrank=toporecv.getProcGroup()->myRank(); + int myrank=toporecv->getProcGroup()->myRank(); + int myworldrank=group->myRank(); for (int iproc=0; iprocsize();iproc++) { int isource = iproc; - if (!toporecv.getProcGroup()->contains(isource)) + if (!toporecv->getProcGroup()->contains(isource)) { int nbelem; - _comm_interface->recv(&nbelem, 1, MPI_INTEGER, isource, tag+myrank, *(group->getComm()), &status); + _comm_interface->recv(&nbelem, 1, MPI_INTEGER, isource, tag+myworldrank, *(group->getComm()), &status); int* buffer = new int[nbelem]; - _comm_interface->recv(buffer, nbelem, MPI_INTEGER, isource,tag+myrank, *(group->getComm()), &status); + _comm_interface->recv(buffer, nbelem, MPI_INTEGER, isource,tag+myworldrank, *(group->getComm()), &status); ExplicitTopology* topotemp=new ExplicitTopology(); topotemp->unserialize(buffer, *_comm_interface); delete[] buffer; - for (int ielem=0; ielemgetNbLocalElements(); ielem++) { - int global=toporecv.localToGlobal(make_pair(iproc,ielem)); + int global = toporecv->localToGlobal(ielem); + //int global=toporecv->localToGlobal(make_pair(iproc,ielem)); int sendlocal=topotemp->globalToLocal(global); if (sendlocal!=-1) { size[iproc]++; - _distant_elems.insert(make_pair(ielem, make_pair(iproc,sendlocal))); + _explicit_mapping.pushBackElem(make_pair(iproc,sendlocal)); + //_distant_elems.insert(make_pair(ielem, make_pair(iproc,sendlocal))); } } delete topotemp; @@ -222,42 +238,129 @@ void ExplicitCoincidentDEC::broadcastTopology(const ExplicitTopology& toposend, MESSAGE (" rank "<myRank()<< " broadcastTopology is over"); } +void ExplicitCoincidentDEC::transferMappingToSource() +{ + + MPIProcessorGroup* group=new MPIProcessorGroup(*_comm_interface); + + // sending source->target mapping which is stored by target + //in _distant_elems from target to source + if (_topotarget!=0 && _topotarget->getProcGroup()->containsMyRank()) + { + int world_size = _topotarget->getProcGroup()->getCommInterface().worldSize() ; + int* nb_transfer_union=new int[world_size]; + int* dummy_recv=new int[world_size]; + for (int i=0; igetProcGroup()->createComplementProcGroup(); + int unionrank=group->translateRank(_sourcegroup,_explicit_mapping.getDistantDomain(i)); + nb_transfer_union[unionrank]=_explicit_mapping.getNbDistantElems(i); + // delete sourcegroup; + } + _comm_interface->allToAll(nb_transfer_union, 1, MPI_INTEGER, dummy_recv, 1, MPI_INTEGER, MPI_COMM_WORLD); + + int* sendbuffer= _explicit_mapping.serialize(_topotarget->getProcGroup()->myRank()); + + int* sendcounts= new int [world_size]; + int* senddispls = new int [world_size]; + for (int i=0; i< world_size; i++) + { + sendcounts[i]=2*nb_transfer_union[i]; + if (i==0) + senddispls[i]=0; + else + senddispls[i]=senddispls[i-1]+sendcounts[i-1]; + } + int* recvcounts=new int[world_size]; + int* recvdispls=new int[world_size]; + int *dummyrecv; + for (int i=0; i allToAllV(sendbuffer, sendcounts, senddispls, MPI_INTEGER, dummyrecv, recvcounts, senddispls, MPI_INTEGER, MPI_COMM_WORLD); + + } + //receiving in the source subdomains the mapping sent by targets + else + { + int world_size = _toposource->getProcGroup()->getCommInterface().worldSize() ; + int* nb_transfer_union=new int[world_size]; + int* dummy_send=new int[world_size]; + for (int i=0; iallToAll(dummy_send, 1, MPI_INTEGER, nb_transfer_union, 1, MPI_INTEGER, MPI_COMM_WORLD); + + int total_size=0; + for (int i=0; i< world_size; i++) + total_size+=nb_transfer_union[i]; + int nbtarget = _targetgroup->size(); + int* targetranks = new int[ nbtarget]; + for (int i=0; itranslateRank(_targetgroup,i); + int* mappingbuffer= new int [total_size*2]; + int* sendcounts= new int [world_size]; + int* senddispls = new int [world_size]; + int* recvcounts=new int[world_size]; + int* recvdispls=new int[world_size]; + for (int i=0; i< world_size; i++) + { + recvcounts[i]=2*nb_transfer_union[i]; + if (i==0) + recvdispls[i]=0; + else + recvdispls[i]=recvdispls[i-1]+recvcounts[i-1]; + } + + int *dummysend; + for (int i=0; i allToAllV(dummysend, sendcounts, senddispls, MPI_INTEGER, mappingbuffer, recvcounts, recvdispls, MPI_INTEGER, MPI_COMM_WORLD); + + _explicit_mapping.unserialize(world_size,nb_transfer_union,nbtarget, targetranks, mappingbuffer); + } +} + void ExplicitCoincidentDEC::recvData() { //MPI_COMM_WORLD is used instead of group because there is no //mechanism for creating the union group yet MESSAGE("recvData"); - for (int i=0; i< 4; i++) - cout << _recvcounts[i]<<" "; - cout <allToAllV(_sendbuffer, _sendcounts, _senddispls, MPI_DOUBLE, _recvbuffer, _recvcounts, _recvdispls, MPI_DOUBLE,MPI_COMM_WORLD); cout<<"end AllToAll"<getNbLocalElements(); - double* value=new double[nb_local]; + double* value=new double[nb_local*_topotarget->getNbComponents()]; int myranktarget=_topotarget->getProcGroup()->myRank(); - vector counters(_toposource->getProcGroup()->size()); + vector counters(_sourcegroup->size()); counters[0]=0; - for (int i=0; i<_toposource->getProcGroup()->size()-1; i++) + for (int i=0; i<_sourcegroup->size()-1; i++) { MPIProcessorGroup* group=new MPIProcessorGroup(*_comm_interface); - int worldrank=group->translateRank(_toposource->getProcGroup(),i); + int worldrank=group->translateRank(_sourcegroup,i); counters[i+1]=counters[i]+_recvcounts[worldrank]; } for (int ielem=0; ielemlocalToGlobal(make_pair(myranktarget, ielem)); - int source_local =_toposource->globalToLocal(global); - value[ielem]=_recvbuffer[counters[source_local]++]; - } - - + pair distant_numbering=_explicit_mapping.getDistantNumbering(ielem); + int iproc=distant_numbering.first; + int ncomp = _topotarget->getNbComponents(); + for (int icomp=0; icomp< ncomp; icomp++) + value[ielem*ncomp+icomp]=_recvbuffer[counters[iproc]*ncomp+icomp]; + counters[iproc]++; + } _target_field->getField()->setValue(value); } diff --git a/src/ParaMEDMEM/ExplicitCoincidentDEC.hxx b/src/ParaMEDMEM/ExplicitCoincidentDEC.hxx index 58fc1548b..43e3204f1 100644 --- a/src/ParaMEDMEM/ExplicitCoincidentDEC.hxx +++ b/src/ParaMEDMEM/ExplicitCoincidentDEC.hxx @@ -2,39 +2,44 @@ #define ExplicitCOINCIDENTDEC_HXX_ #include "DEC.hxx" +#include "ExplicitMapping.hxx" #include "ExplicitTopology.hxx" #include namespace ParaMEDMEM { -class DEC; -class BlockTopology; -class ExplicitCoincidentDEC: public DEC -{ -public: - ExplicitCoincidentDEC(); - virtual ~ExplicitCoincidentDEC(); - void synchronize(); - void broadcastTopology(BlockTopology*&, int tag); - void broadcastTopology(const ExplicitTopology& toposend, ExplicitTopology& toporecv, int tag); - - void prepareSourceDE(); - void prepareTargetDE(); - void recvData(); - void sendData(); -private : - - ExplicitTopology* _toposource; - ExplicitTopology* _topotarget; - int* _sendcounts; - int* _recvcounts; - int* _senddispls; - int* _recvdispls; - double* _recvbuffer; - double* _sendbuffer; - std::map > _distant_elems; -}; - + class DEC; + class BlockTopology; + // class ExplicitMapping; + class ExplicitCoincidentDEC: public DEC + { + public: + ExplicitCoincidentDEC(); + virtual ~ExplicitCoincidentDEC(); + void synchronize(); + void broadcastTopology(BlockTopology*&, int tag); + void broadcastTopology(const ExplicitTopology* toposend, ExplicitTopology* toporecv, int tag); + void transferMappingToSource(); + void prepareSourceDE(); + void prepareTargetDE(); + void recvData(); + void sendData(); + private : + + ExplicitTopology* _toposource; + ExplicitTopology* _topotarget; + ProcessorGroup* _targetgroup; + ProcessorGroup* _sourcegroup; + int* _sendcounts; + int* _recvcounts; + int* _senddispls; + int* _recvdispls; + double* _recvbuffer; + double* _sendbuffer; + std::map > _distant_elems; + ExplicitMapping _explicit_mapping; + }; + } #endif /*ExplicitCOINCIDENTDEC_HXX_*/ diff --git a/src/ParaMEDMEM/ExplicitTopology.cxx b/src/ParaMEDMEM/ExplicitTopology.cxx index e953bfe94..3ba799f73 100644 --- a/src/ParaMEDMEM/ExplicitTopology.cxx +++ b/src/ParaMEDMEM/ExplicitTopology.cxx @@ -19,7 +19,9 @@ namespace ParaMEDMEM { ExplicitTopology::ExplicitTopology(const ParaSUPPORT& parasupport ): -_proc_group(parasupport.getMesh()->getBlockTopology()->getProcGroup()){ +_proc_group(parasupport.getMesh()->getBlockTopology()->getProcGroup()), +_nb_components(1) +{ _nb_elems=parasupport.getSupport()->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS); MED_EN::medEntityMesh entity= parasupport.getSupport()->getEntity(); const int* global=parasupport.getMesh()->getGlobalNumbering(entity); @@ -45,6 +47,19 @@ _proc_group(parasupport.getMesh()->getBlockTopology()->getProcGroup()){ } } +ExplicitTopology::ExplicitTopology(const ExplicitTopology& topo, int nb_components) +{ + _proc_group = topo._proc_group; + _nb_elems = topo._nb_elems; + _nb_components = nb_components; + _loc2glob=new int[2*_nb_elems]; + for (int i=0; i<2*_nb_elems; i++) + { + _loc2glob[i]=topo._loc2glob[i]; + } + _glob2loc=topo._glob2loc; +} + ExplicitTopology::~ExplicitTopology() { @@ -76,13 +91,14 @@ void ExplicitTopology::unserialize(const int* serializer,const CommInterface& co { const int* ptr_serializer=serializer; cout << "unserialize..."< _glob2loc; + //Processor group + const ProcessorGroup* _proc_group; + //nb of elements + int _nb_elems; + //nb of components + int _nb_components; + //mapping local to global + int* _loc2glob; + //mapping global to local + hash_map _glob2loc; }; //!converts a pair to a global number diff --git a/src/ParaMEDMEM/MPIProcessorGroup.cxx b/src/ParaMEDMEM/MPIProcessorGroup.cxx index 34a84019e..3f6330753 100644 --- a/src/ParaMEDMEM/MPIProcessorGroup.cxx +++ b/src/ParaMEDMEM/MPIProcessorGroup.cxx @@ -5,7 +5,7 @@ #include #include #include -#include "/export/home/vb144235/mpich2_install/include/mpi.h" +#include "mpi.h" using namespace std; @@ -71,5 +71,26 @@ int MPIProcessorGroup::translateRank(const ProcessorGroup* group, int rank) cons } +ProcessorGroup* MPIProcessorGroup::createComplementProcGroup() const +{ + set procs; + int world_size=_comm_interface.worldSize(); + for (int i=0; i::const_iterator iter=_proc_ids.begin(); iter!= _proc_ids.end(); iter++) + procs.erase(*iter); + + return new MPIProcessorGroup(_comm_interface, procs); + +} +ProcessorGroup* MPIProcessorGroup::createProcGroup() const +{ + set procs; + for (set::const_iterator iter=_proc_ids.begin(); iter!= _proc_ids.end(); iter++) + procs.insert(*iter); + + return new MPIProcessorGroup(_comm_interface, procs); + +} } diff --git a/src/ParaMEDMEM/MPIProcessorGroup.hxx b/src/ParaMEDMEM/MPIProcessorGroup.hxx index 9a5e7043b..aa0d49ea4 100644 --- a/src/ParaMEDMEM/MPIProcessorGroup.hxx +++ b/src/ParaMEDMEM/MPIProcessorGroup.hxx @@ -23,6 +23,9 @@ public: bool containsMyRank() const { int rank; MPI_Group_rank(_group, &rank); return (rank!=MPI_UNDEFINED);} int translateRank(const ProcessorGroup* group, int rank) const; const MPI_Comm* getComm() const {return &_comm;} + ProcessorGroup* createComplementProcGroup() const; + ProcessorGroup* createProcGroup() const; + private: MPI_Group _group; MPI_Comm _comm; diff --git a/src/ParaMEDMEM/Makefile.in b/src/ParaMEDMEM/Makefile.in index 5daf5c465..3cd41cd22 100644 --- a/src/ParaMEDMEM/Makefile.in +++ b/src/ParaMEDMEM/Makefile.in @@ -53,7 +53,9 @@ ExplicitTopology.hxx\ ParaFIELD.hxx\ DEC.hxx\ StructuredCoincidentDEC.hxx\ -ExplicitCoincidentDEC.hxx +UnstructuredParaSUPPORT.hxx\ +ExplicitCoincidentDEC.hxx\ +ExplicitMapping.hxx # Libraries targets @@ -71,6 +73,7 @@ ParaFIELD.cxx\ DEC.cxx\ StructuredCoincidentDEC.cxx\ ExplicitCoincidentDEC.cxx\ +UnstructuredParaSUPPORT.cxx\ ExplicitTopology.cxx @@ -82,22 +85,22 @@ BIN_SERVER_IDL = BIN_CLIENT_IDL = TEST_PROGS = test_ProcessorGroup test_BlockTopology test_ParaStructuredSupport \ -test_ParaField test_DEC test_UnstructuredDEC +test_ParaField test_DEC test_UnstructuredDEC test_ExplicitDEC LDFLAGS+= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome LDFLAGSFORBIN+= -L$(top_builddir)/lib@LIB_LOCATION_SUFFIX@/salome -CPPFLAGS+=$(MED2_INCLUDES) $(HDF5_INCLUDES) $(MPI_INCLUDES) +CPPFLAGS+=$(MED2_INCLUDES) $(MPI_INCLUDES) $(LAM_INCLUDES) -I/data/tmpawa/vb144235/lam_install/include -CXXFLAGS+=@CXXTMPDPTHFLAGS@ $(MPI_INCLUDES) +CXXFLAGS+=@CXXTMPDPTHFLAGS@ CPPFLAGS+=$(BOOST_CPPFLAGS) #LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) # change motivated by the bug KERNEL4778. -LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -lmed_V2_1 $(STDLIB) -lmedmem $(MPI_LIBS) +LDFLAGS+=$(MED2_LIBS) $(HDF5_LIBS) -lmed_V2_1 $(STDLIB) -lmedmem $(MPI_LIBS) $(LAM_LIBS) -L/data/tmpawa/vb144235/lam_install/lib -lmpi -llam -lutil #LDFLAGSFORBIN+=$(MED2_LIBS) $(HDF5_LIBS) # change motivated by the bug KERNEL4778. -LDFLAGSFORBIN+=-lm $(MED2_LIBS) $(HDF5_LIBS) -lmed_V2_1 -lmedmem $(MPI_LIBS) $(BOOST_LIBS) +LDFLAGSFORBIN+= -lm $(MED2_LIBS) $(HDF5_LIBS) -lmed_V2_1 -lmedmem $(BOOST_LIBS) $(MPI_LIBS) $(LAM_LIBS) -L/data/tmpawa/vb144235/lam_install/lib -lmpi -llam -lutil ifeq ($(MED_WITH_KERNEL),yes) CPPFLAGS+= ${KERNEL_CXXFLAGS} diff --git a/src/ParaMEDMEM/ParaFIELD.cxx b/src/ParaMEDMEM/ParaFIELD.cxx index f003519a6..3251a61db 100644 --- a/src/ParaMEDMEM/ParaFIELD.cxx +++ b/src/ParaMEDMEM/ParaFIELD.cxx @@ -4,7 +4,7 @@ #include "ComponentTopology.hxx" #include "ParaSUPPORT.hxx" #include "StructuredParaSUPPORT.hxx" -#include "ExplicitCoincidentDEC.hxx"; +#include "ExplicitCoincidentDEC.hxx" #include "StructuredCoincidentDEC.hxx" #include "ParaFIELD.hxx" #include "ParaMESH.hxx" @@ -14,19 +14,27 @@ using namespace MEDMEM; namespace ParaMEDMEM { -ParaFIELD::ParaFIELD(ParaSUPPORT* para_support, const ComponentTopology& component_topology) +ParaFIELD::ParaFIELD(const ParaSUPPORT* para_support, const ComponentTopology& component_topology) :_support(para_support), _component_topology(component_topology) { - if (dynamic_cast(para_support)!=0) + if (dynamic_cast(para_support)!=0) {const BlockTopology* source_topo = dynamic_cast(para_support->getTopology()); _topology=new BlockTopology(*source_topo,component_topology); } else - throw MEDEXCEPTION(LOCALIZED( + { + if (component_topology.nbBlocks()!=1) + throw MEDEXCEPTION(LOCALIZED( "ParaFIELD constructor : Unstructured Support not taken into account with component topology yet")); - - + else + { + const ExplicitTopology* source_topo= + dynamic_cast (para_support->getTopology()); + _topology=new ExplicitTopology(*source_topo,component_topology.nbLocalComponents()); + + } + } // int nb_components=0; // if (component_topology.getProcGroup()!=0) int nb_components = component_topology.nbLocalComponents(); @@ -61,8 +69,8 @@ ParaFIELD::ParaFIELD(MEDMEM::driverTypes driver_type, const string& file_name, ParaFIELD::~ParaFIELD(){} void ParaFIELD::write(MEDMEM::driverTypes driverType, const string& fileName, const string& meshName){ - BlockTopology* topo = dynamic_cast (_topology); - int myrank = topo->getProcGroup()->myRank(); + // Topology* topo = dynamic_cast (_topology); + int myrank = _topology->getProcGroup()->myRank(); ostringstream name; name <attachTargetField(this); data_channel->synchronize(); data_channel->prepareTargetDE(); - data_channel->sendData(); + data_channel->recvData(); delete data_channel; } diff --git a/src/ParaMEDMEM/ParaFIELD.hxx b/src/ParaMEDMEM/ParaFIELD.hxx index 88348e59d..7e5fac29d 100644 --- a/src/ParaMEDMEM/ParaFIELD.hxx +++ b/src/ParaMEDMEM/ParaFIELD.hxx @@ -18,7 +18,9 @@ class ParaSUPPORT; class ParaFIELD { public: - ParaFIELD(ParaSUPPORT* support, const ComponentTopology& component_topology); + + ParaFIELD(const ParaSUPPORT* support, const ComponentTopology& component_topology); + ParaFIELD(MEDMEM::driverTypes driver_type, const string& file_name, const string& driver_name, const ComponentTopology& component_topology) throw (MEDMEM::MEDEXCEPTION); @@ -33,7 +35,7 @@ private: const ComponentTopology& _component_topology; Topology* _topology; MEDMEM::FIELD* _field; - ParaSUPPORT* _support; + const ParaSUPPORT* _support; }; } diff --git a/src/ParaMEDMEM/ParaMESH.cxx b/src/ParaMEDMEM/ParaMESH.cxx index c0914d098..45d1579a4 100644 --- a/src/ParaMEDMEM/ParaMESH.cxx +++ b/src/ParaMEDMEM/ParaMESH.cxx @@ -64,6 +64,7 @@ throw (MEDMEM::MEDEXCEPTION){ strcpy(meshname,meshstring.c_str()); strcpy(file,_medfilename.c_str()); } + _name=meshstring; /////////////////////////////////////////// // treatment of the domain that corresponds // to the local id @@ -214,8 +215,7 @@ throw (MEDMEM::MEDEXCEPTION){ int nbdomains= _block_topology->getProcGroup()->size(); vector filename(nbdomains); - - + //loop on the domains for (int i=0; i _connect_zone; //id of the local grid diff --git a/src/ParaMEDMEM/ParaSUPPORT.hxx b/src/ParaMEDMEM/ParaSUPPORT.hxx index 73a22cb19..116664b76 100644 --- a/src/ParaMEDMEM/ParaSUPPORT.hxx +++ b/src/ParaMEDMEM/ParaSUPPORT.hxx @@ -13,6 +13,8 @@ namespace ParaMEDMEM { public: ParaSUPPORT(); + ParaSUPPORT(const ParaMESH* mesh, const MEDMEM::SUPPORT* support): + _support(support), _mesh(mesh){}; ParaSUPPORT(const MEDMEM::SUPPORT&); virtual ~ParaSUPPORT(); virtual const Topology* getTopology() const {}; diff --git a/src/ParaMEDMEM/ProcessorGroup.hxx b/src/ParaMEDMEM/ProcessorGroup.hxx index d58eae0ee..e605bfaf8 100644 --- a/src/ParaMEDMEM/ProcessorGroup.hxx +++ b/src/ParaMEDMEM/ProcessorGroup.hxx @@ -26,7 +26,8 @@ public: const CommInterface& getCommInterface()const {return _comm_interface;}; virtual int myRank() const =0; virtual int translateRank(const ProcessorGroup*, int) const =0; - + virtual ProcessorGroup* createComplementProcGroup() const =0; + virtual ProcessorGroup* createProcGroup() const=0; protected: const CommInterface& _comm_interface; std::set _proc_ids; diff --git a/src/ParaMEDMEM/Topology.hxx b/src/ParaMEDMEM/Topology.hxx index 1ab9434da..87842b750 100644 --- a/src/ParaMEDMEM/Topology.hxx +++ b/src/ParaMEDMEM/Topology.hxx @@ -6,6 +6,7 @@ using namespace std; namespace ParaMEDMEM { + class ProcessorGroup; class Topology { @@ -16,6 +17,7 @@ public: // virtual int localToGlobal (const std::pair) const =0; virtual int getNbElements() const=0; virtual int getNbLocalElements() const =0; + virtual const ProcessorGroup* getProcGroup()const =0; }; } diff --git a/src/ParaMEDMEM/UnstructuredParaSUPPORT.cxx b/src/ParaMEDMEM/UnstructuredParaSUPPORT.cxx index 49c28ba75..f793bc72f 100644 --- a/src/ParaMEDMEM/UnstructuredParaSUPPORT.cxx +++ b/src/ParaMEDMEM/UnstructuredParaSUPPORT.cxx @@ -1,6 +1,6 @@ #include "Topology.hxx" -#include "BlockTopology.hxx" -#include "ParaGRID.hxx" +#include "ExplicitTopology.hxx" +#include "ParaMESH.hxx" #include "UnstructuredParaSUPPORT.hxx" #include "MEDMEM_Support.hxx" @@ -8,15 +8,25 @@ namespace ParaMEDMEM { /*! Constructor on all elements from a MESH */ -UnstructuredParaSUPPORT::UnstructuredParaSUPPORT(const ParaMESH* const mesh, const SUPPORT* support): -_mesh(mesh), +UnstructuredParaSUPPORT::UnstructuredParaSUPPORT(const ParaMESH* const mesh, const MEDMEM::SUPPORT* support): _entity(support->getEntity()), -_support(support), -_block_topology(mesh->getBlockTopology()->getProcGroup(), support->getNumberOfElements(MED_EN::MED_ALL_ELEMENTS)) +_explicit_topology(new ExplicitTopology(*support)) { + _mesh=mesh; + _support=support; } -StructuredParaSUPPORT::~StructuredParaSUPPORT() +UnstructuredParaSUPPORT::UnstructuredParaSUPPORT(const ParaMESH* const mesh, const MED_EN::medEntityMesh entity): + ParaSUPPORT(mesh, new MEDMEM::SUPPORT(mesh->getMesh(), "support on all entities", entity)), + _entity(entity), + _explicit_topology(new ExplicitTopology(*this)) +{ + //_mesh=mesh; + // _support=new SUPPORT(_mesh->getMesh(), "support on all entities", entity); + //_explicit_topology(new ExplicitTopology(*support)); +} + +UnstructuredParaSUPPORT::~UnstructuredParaSUPPORT() { delete _support; } diff --git a/src/ParaMEDMEM/UnstructuredParaSUPPORT.hxx b/src/ParaMEDMEM/UnstructuredParaSUPPORT.hxx index 7d30c5de4..cc2ad70b8 100644 --- a/src/ParaMEDMEM/UnstructuredParaSUPPORT.hxx +++ b/src/ParaMEDMEM/UnstructuredParaSUPPORT.hxx @@ -3,6 +3,7 @@ #include "ParaSUPPORT.hxx" #include "MEDMEM_define.hxx" +#include "ExplicitTopology.hxx" using namespace MED_EN; namespace MEDMEM @@ -12,23 +13,25 @@ namespace MEDMEM namespace ParaMEDMEM { -class BlockTopology; -class ParaMESH; + class Topology; + class ExplicitTopology; + class ParaMESH; + -class UnstructuredParaSUPPORT:public ParaSUPPORT -{ -public: - - UnstructuredParaSUPPORT(const ParaMESH* const mesh, SUPPORT* support ); - virtual ~UnstructuredParaSUPPORT(); - const Topology* getTopology() const {return _block_topology;} - -private: - const BlockTopology* const _block_topology; - const MED_EN::medEntityMesh _entity; + class UnstructuredParaSUPPORT:public ParaSUPPORT + { + public: + + UnstructuredParaSUPPORT(const ParaMESH* const mesh, const MEDMEM::SUPPORT* support ); + UnstructuredParaSUPPORT(const ParaMESH* const mesh, const MED_EN::medEntityMesh entity); + virtual ~UnstructuredParaSUPPORT(); + const Topology* getTopology() const {return _explicit_topology;} + + private: + const ExplicitTopology* const _explicit_topology; + const MED_EN::medEntityMesh _entity; - -}; - + }; + } #endif /*STRUCTUREDPARASUPPORT_HXX_*/ diff --git a/src/ParaMEDMEM/test_ExplicitDEC.cxx b/src/ParaMEDMEM/test_ExplicitDEC.cxx index 70fc5f823..3237b7b8d 100644 --- a/src/ParaMEDMEM/test_ExplicitDEC.cxx +++ b/src/ParaMEDMEM/test_ExplicitDEC.cxx @@ -13,7 +13,7 @@ #include "MPIProcessorGroup.hxx" #include "MEDMEM_Mesh.hxx" #include "ParaMESH.hxx" -#include "StructuredParaSUPPORT.hxx" +#include "UnstructuredParaSUPPORT.hxx" #include "ComponentTopology.hxx" #include "ParaFIELD.hxx" @@ -58,17 +58,17 @@ int main(int argc, char** argv) Topology* topo_target; if (source_group->containsMyRank()) { - source_mesh=new ParaMESH(MED_DRIVER,"../../share/salome/resources/pointe_nosplit",*self_group); + source_mesh=new ParaMESH(MED_DRIVER,"../../share/salome/resources/med/pointe_nosplit",*source_group); topo_source=source_mesh->getBlockTopology(); } if (target_group->containsMyRank()) { - target_mesh=new ParaMESH(MED_DRIVER,"../../share/salome/resources/pointe_split",*target_group); + target_mesh=new ParaMESH(MED_DRIVER,"../../share/salome/resources/med/pointe_split",*target_group); topo_target=target_mesh->getBlockTopology(); } - StructuredParaSUPPORT* target_support; - StructuredParaSUPPORT* source_support; + UnstructuredParaSUPPORT* target_support; + UnstructuredParaSUPPORT* source_support; ComponentTopology* target_comp; ComponentTopology* source_comp; ParaFIELD* target_field=0; @@ -76,9 +76,9 @@ int main(int argc, char** argv) if (source_group->containsMyRank()) { - source_support=new StructuredParaSUPPORT(source_mesh,MED_EN::MED_CELL); - source_comp=new ComponentTopology (6, source_group); - source_field = new ParaFIELD(source_support, *source_comp); + source_support=new UnstructuredParaSUPPORT(source_mesh,MED_EN::MED_CELL); + source_comp=new ComponentTopology (1); + source_field = new ParaFIELD(source_support,*source_comp); int nb_local = source_field->getTopology()->getNbLocalElements(); cout << "Source field nb elems on rank : "<synchronizeSource(target_field); if (source_group->myRank()==0) { - source_mesh->write(MED_DRIVER,"/home/vb144235/tmp/source"); - source_field->write(MED_DRIVER,"/home/vb144235/tmp/source","maa1"); + source_mesh->write(MED_DRIVER,"/home/vb144235/tmp/sourceexp"); + source_field->write(MED_DRIVER,"/home/vb144235/tmp/sourceexp","maa1"); } } if (target_group->containsMyRank()) { - target_support=new StructuredParaSUPPORT(target_mesh,MED_EN::MED_CELL); - target_comp= new ComponentTopology (6); - target_field = new ParaFIELD(target_support, *target_comp); + target_support=new UnstructuredParaSUPPORT(target_mesh,MED_EN::MED_CELL); + target_comp=new ComponentTopology(1); + target_field = new ParaFIELD(target_support,*target_comp); target_field->synchronizeTarget(source_field); - target_mesh->write(MED_DRIVER, "/home/vb144235/tmp/target"); - target_field->write(MED_DRIVER, "/home/vb144235/tmp/target", "maa1"); + target_mesh->write(MED_DRIVER, "/home/vb144235/tmp/targetexp"); + target_field->write(MED_DRIVER, "/home/vb144235/tmp/targetexp", "maa1_1"); } MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); diff --git a/src/ParaMEDMEM/test_ParaField.cxx b/src/ParaMEDMEM/test_ParaField.cxx index 2c4be32b8..5bb26f235 100644 --- a/src/ParaMEDMEM/test_ParaField.cxx +++ b/src/ParaMEDMEM/test_ParaField.cxx @@ -23,6 +23,7 @@ using namespace ParaMEDMEM; using namespace MEDMEM; int main(int argc, char** argv) { + string testname="ParaMEDMEM - test #1 -"; MPI_Init(&argc, &argv); int size; @@ -74,6 +75,7 @@ int main(int argc, char** argv) } MPI_Finalize(); return 0; + }