Back to index

salome-med  6.5.0
Public Member Functions | Private Attributes
ParaMEDMEM::BlockTopology Class Reference

#include <BlockTopology.hxx>

Inheritance diagram for ParaMEDMEM::BlockTopology:
Inheritance graph
[legend]
Collaboration diagram for ParaMEDMEM::BlockTopology:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 BlockTopology ()
 BlockTopology (const ProcessorGroup &group, MEDCouplingCMesh *grid)
 Constructor of a block topology from a grid.
 BlockTopology (const BlockTopology &geom_topo, const ComponentTopology &comp_topo)
 Creation of a block topology by composing a geometrical topology and a component topology.
 BlockTopology (const ProcessorGroup &group, int nb_elem)
 Constructor for creating a one-dimensional topology from a processor group and a local number of elements on each processor.
virtual ~BlockTopology ()
int getNbElements () const
 Retrieves the number of elements for a given topology.
int getNbLocalElements () const
const ProcessorGroupgetProcGroup () const
std::pair< int, int > globalToLocal (const int) const
 converts a pair <subdomainid,local> to a global number
int localToGlobal (const std::pair< int, int >) const
 converts local number to a global number
std::vector< std::pair< int,
int > > 
getLocalArrayMinMax () const
 Retrieves the min and max indices of the domain stored locally for each dimension.
int getDimension () const
void serialize (int *&serializer, int &size) const
 Serializes the data contained in the Block Topology for communication purposes.
void unserialize (const int *serializer, const CommInterface &comm_interface)
 Unserializes the data contained in the Block Topology after communication.

Private Attributes

int _dimension
std::vector< int > _nb_procs_per_dim
std::vector< std::vector< int > > _local_array_indices
std::vector< CYCLE_TYPE_cycle_type
const ProcessorGroup_proc_group
int _nb_elems
bool _owns_processor_group

Detailed Description

Definition at line 35 of file BlockTopology.hxx.


Constructor & Destructor Documentation

Definition at line 38 of file BlockTopology.hxx.

{ }

Constructor of a block topology from a grid.

This preliminary version simply splits along the first axis instead of making the best choice with respect to the values of the different axes.

Definition at line 127 of file BlockTopology.cxx.

                                                                                 :
    _dimension(grid->getSpaceDimension()), _proc_group(&group), _owns_processor_group(false)
  {
    vector <int> axis_length(_dimension);
    _nb_elems=1;
    for (int idim=0; idim <_dimension; idim++)
      {
        DataArrayDouble *arr=grid->getCoordsAt(idim);
        axis_length[idim]=arr->getNbOfElems();
        _nb_elems*=axis_length[idim];
      }  
    //default splitting along 1st dimension
    _local_array_indices.resize(_dimension);
    _nb_procs_per_dim.resize(_dimension);
  
    _local_array_indices[0].resize(_proc_group->size()+1);
    _local_array_indices[0][0]=0;
    _nb_procs_per_dim[0]=_proc_group->size();
  
    for (int i=1; i<=_proc_group->size(); i++)
      {
        _local_array_indices[0][i]=_local_array_indices[0][i-1]+
          axis_length[0]/_proc_group->size();
        if (i<= axis_length[0]%_proc_group->size())
          _local_array_indices[0][i]+=1;
      }
    for (int i=1; i<_dimension; i++)
      {
        _local_array_indices[i].resize(2);
        _local_array_indices[i][0]=0;
        _local_array_indices[i][1]=axis_length[i];
        _nb_procs_per_dim[i]=1;
      }
    _cycle_type.resize(_dimension);
    for (int i=0; i<_dimension; i++)
      _cycle_type[i]=ParaMEDMEM::Block;  
  }

Here is the call graph for this function:

ParaMEDMEM::BlockTopology::BlockTopology ( const BlockTopology geom_topo,
const ComponentTopology comp_topo 
)

Creation of a block topology by composing a geometrical topology and a component topology.

This constructor is intended for creating fields for which the parallel distribution is made on the components of the field rather than on the geometrical partitioning of the underlying mesh.

Definition at line 174 of file BlockTopology.cxx.

                                                                                                :_owns_processor_group(false)
  {
    // so far, the block topology can only be created if the proc group 
    // is either on geom_topo or on comp_topo
    if (geom_topo.getProcGroup()->size()>1 && comp_topo.nbBlocks()>1)
      throw INTERP_KERNEL::Exception(LOCALIZED("BlockTopology cannot yet be constructed with both complex geo and components topology"));

    if (comp_topo.nbComponents()==1)
      {
        *this=geom_topo;
        return;
      }
    else
      {
        _dimension = geom_topo.getDimension()+1;
        if (comp_topo.nbBlocks()>1)
          _proc_group=comp_topo.getProcGroup();
        else
          _proc_group=geom_topo.getProcGroup();
        _local_array_indices=geom_topo._local_array_indices;
        vector<int> comp_indices = *(comp_topo.getBlockIndices());
        _local_array_indices.push_back(comp_indices);
        _nb_procs_per_dim=geom_topo._nb_procs_per_dim;
        _nb_procs_per_dim.push_back(comp_topo.nbBlocks());
        _cycle_type=geom_topo._cycle_type;
        _cycle_type.push_back(Block);
        _nb_elems=geom_topo.getNbElements()*comp_topo.nbComponents();
      }  
  }

Here is the call graph for this function:

ParaMEDMEM::BlockTopology::BlockTopology ( const ProcessorGroup group,
int  nb_elem 
)

Constructor for creating a one-dimensional topology from a processor group and a local number of elements on each processor.

The function must be called only by the processors belonging to group group. Calling it from a processor not belonging to group will cause an MPI error, while calling from a subset of group will result in a deadlock.

Definition at line 213 of file BlockTopology.cxx.

                                                                      :_dimension(1),_proc_group(&group),_owns_processor_group(false)
  {
    int* nbelems_per_proc = new int[group.size()];
    const MPIProcessorGroup* mpi_group=dynamic_cast<const MPIProcessorGroup*>(_proc_group);
    const MPI_Comm* comm=mpi_group->getComm();
    int nbtemp=nb_elem;
    mpi_group->getCommInterface().allGather(&nbtemp, 1, MPI_INT, 
                                            nbelems_per_proc, 1, MPI_INT, 
                                            *comm);
    _nb_elems=0;  
  
    //splitting along only dimension
    _local_array_indices.resize(1);
    _nb_procs_per_dim.resize(1);  
          
    _local_array_indices[0].resize(_proc_group->size()+1);
    _local_array_indices[0][0]=0;
    _nb_procs_per_dim[0]=_proc_group->size();
  
    for (int i=1; i<=_proc_group->size(); i++)
      {
        _local_array_indices[0][i]=_local_array_indices[0][i-1]+
          nbelems_per_proc[i-1];
        _nb_elems+=nbelems_per_proc[i-1];
      }
    _cycle_type.resize(1);
    _cycle_type[0]=ParaMEDMEM::Block;
    delete[] nbelems_per_proc;
  }

Here is the call graph for this function:

Definition at line 243 of file BlockTopology.cxx.


Member Function Documentation

Definition at line 50 of file BlockTopology.hxx.

{ return _dimension; }

Here is the caller graph for this function:

std::vector< std::pair< int, int > > ParaMEDMEM::BlockTopology::getLocalArrayMinMax ( ) const

Retrieves the min and max indices of the domain stored locally for each dimension.

The output vector has the topology dimension as a size and each pair <int,int> contains min and max. Indices range from min to max-1.

Definition at line 254 of file BlockTopology.cxx.

  {
    vector<pair<int,int> > local_indices (_dimension);
    int myrank=_proc_group->myRank();
    int increment=1;
    for (int i=_dimension-1; i>=0; i--)
      {  
        increment *=_nb_procs_per_dim[i];
        int idim=myrank%increment;
        local_indices[i].first=_local_array_indices[i][idim];
        local_indices[i].second=_local_array_indices[i][idim+1];
        cout << local_indices[i].first << " "<< local_indices[i].second<<endl;
      }
    return local_indices;
  }

Here is the call graph for this function:

int ParaMEDMEM::BlockTopology::getNbElements ( ) const [inline, virtual]

Retrieves the number of elements for a given topology.

Implements ParaMEDMEM::Topology.

Definition at line 44 of file BlockTopology.hxx.

{ return _nb_elems; }

Here is the caller graph for this function:

Implements ParaMEDMEM::Topology.

Definition at line 104 of file BlockTopology.cxx.

  {
    int position=_proc_group->myRank();
    int nb_elem = 1;
    int increment=1;
    for (int i=_dimension-1; i>=0; i--)
      {  
        increment *=_nb_procs_per_dim[i];
        int idim=position%increment;
        position=position/increment;
        int imin=_local_array_indices[i][idim];
        int imax=_local_array_indices[i][idim+1];
        nb_elem*=(imax-imin);
      }
    return nb_elem;
  }

Here is the caller graph for this function:

const ProcessorGroup* ParaMEDMEM::BlockTopology::getProcGroup ( ) const [inline, virtual]

Implements ParaMEDMEM::Topology.

Definition at line 46 of file BlockTopology.hxx.

{ return _proc_group; }

Here is the caller graph for this function:

std::pair< int, int > ParaMEDMEM::BlockTopology::globalToLocal ( const int  global) const

converts a pair <subdomainid,local> to a global number

Definition at line 40 of file BlockTopology.cxx.

  {
    int subdomain_id=0;
    int position=global;
    int size=_nb_elems;
    int size_procs=_proc_group->size();
    int increment=size;
    vector<int>axis_position(_dimension);
    vector<int>axis_offset(_dimension);
    for (int idim=0; idim<_dimension; idim++)
      {
        int axis_size=_local_array_indices[idim].size()-1;
        int axis_nb_elem=_local_array_indices[idim][axis_size];
        increment=increment/axis_nb_elem;
        int proc_increment = size_procs/(axis_size);
        int axis_pos=position/increment;
        position=position%increment;  
        int iaxis=1;
        while (_local_array_indices[idim][iaxis]<=axis_pos)
          {
            subdomain_id+=proc_increment;
            iaxis++;
          }
        axis_position[idim]=axis_pos-_local_array_indices[idim][iaxis-1];
        axis_offset[idim]=iaxis;
      }
    int local=0;
    int local_increment=1;
    for (int idim=_dimension-1; idim>=0; idim--)
      {
        local+=axis_position[idim]*local_increment;
        local_increment*=_local_array_indices[idim][axis_offset[idim]]-_local_array_indices[idim][axis_offset[idim]-1];
      }
    return make_pair(subdomain_id,local);
  }

Here is the caller graph for this function:

int ParaMEDMEM::BlockTopology::localToGlobal ( const std::pair< int, int >  ) const

converts local number to a global number

Definition at line 77 of file BlockTopology.cxx.

  {
  
    int subdomain_id=local.first;
    int global=0;
    int loc=local.second;
    int increment=_nb_elems;
    int proc_increment=_proc_group->size();
    int local_increment=getNbLocalElements();
    for (int idim=0; idim < _dimension; idim++)
      {
        int axis_size=_local_array_indices[idim].size()-1;
        int axis_nb_elem=_local_array_indices[idim][axis_size];
        increment=axis_nb_elem==0?0:increment/axis_nb_elem;
        proc_increment = proc_increment/(axis_size);
        int proc_axis=subdomain_id/proc_increment;
        subdomain_id=subdomain_id%proc_increment;
        int local_axis_nb_elem=_local_array_indices[idim][proc_axis+1]-_local_array_indices[idim][proc_axis];
        local_increment = (local_axis_nb_elem==0)?0:(local_increment/local_axis_nb_elem);
        int iaxis=((local_increment==0)?0:(loc/local_increment))+_local_array_indices[idim][proc_axis];
        global+=increment*iaxis;
        loc = (local_increment==0)?0:(loc%local_increment);
      }
    return global;
  }

Here is the caller graph for this function:

void ParaMEDMEM::BlockTopology::serialize ( int *&  serializer,
int &  size 
) const

Serializes the data contained in the Block Topology for communication purposes.

Definition at line 272 of file BlockTopology.cxx.

  {
    vector<int> buffer;
  
    buffer.push_back(_dimension);
    buffer.push_back(_nb_elems);
    for (int i=0; i<_dimension; i++)
      {
        buffer.push_back(_nb_procs_per_dim[i]);
        buffer.push_back(_cycle_type[i]);
        buffer.push_back(_local_array_indices[i].size());
        for (int j=0; j<(int)_local_array_indices[i].size(); j++)
          buffer.push_back(_local_array_indices[i][j]);
      }
  
    //serializing the comm group
    int size_comm=_proc_group->size();
    buffer.push_back(size_comm);
    MPIProcessorGroup world_group(_proc_group->getCommInterface());
    for (int i=0; i<size_comm;i++)
      {
        int world_rank=world_group.translateRank(_proc_group, i);
        buffer.push_back(world_rank);
      }
  
    serializer=new int[buffer.size()];
    size=buffer.size();
    copy(buffer.begin(), buffer.end(), serializer);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

void ParaMEDMEM::BlockTopology::unserialize ( const int *  serializer,
const CommInterface comm_interface 
)

Unserializes the data contained in the Block Topology after communication.

Uses the same structure as the one used for serialize()

Definition at line 308 of file BlockTopology.cxx.

  {
    const int* ptr_serializer=serializer;
    cout << "unserialize..."<<endl;
    _dimension=*(ptr_serializer++);
    cout << "dimension "<<_dimension<<endl;
    _nb_elems=*(ptr_serializer++);
    cout << "nbelems "<<_nb_elems<<endl;
    _nb_procs_per_dim.resize(_dimension);
    _cycle_type.resize(_dimension);
    _local_array_indices.resize(_dimension);
    for (int i=0; i<_dimension; i++)
      {
        _nb_procs_per_dim[i]=*(ptr_serializer++);
        _cycle_type[i]=(CYCLE_TYPE)*(ptr_serializer++);
        _local_array_indices[i].resize(*(ptr_serializer++));
        for (int j=0; j<(int)_local_array_indices[i].size(); j++)
          _local_array_indices[i][j]=*(ptr_serializer++);
      }
    set<int> procs;
    int size_comm=*(ptr_serializer++);
    for (int i=0; i<size_comm; i++)
      procs.insert(*(ptr_serializer++));
    cout << "unserialize..."<<procs.size()<<endl;
    _proc_group=new MPIProcessorGroup(comm_interface,procs);
    _owns_processor_group=true;
    //TODO manage memory ownership of _proc_group  
  }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 61 of file BlockTopology.hxx.

Definition at line 55 of file BlockTopology.hxx.

std::vector<std::vector<int> > ParaMEDMEM::BlockTopology::_local_array_indices [private]

Definition at line 59 of file BlockTopology.hxx.

Definition at line 65 of file BlockTopology.hxx.

Definition at line 57 of file BlockTopology.hxx.

Definition at line 66 of file BlockTopology.hxx.

Definition at line 63 of file BlockTopology.hxx.


The documentation for this class was generated from the following files: