Loading...
Searching...
No Matches
distributor.h
Go to the documentation of this file.
#ifndef _RHEO_DISTRIBUTOR_H
#define _RHEO_DISTRIBUTOR_H
//
// This file is part of Rheolef.
//
// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
//
// Rheolef is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// Rheolef 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Rheolef; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// =========================================================================
// AUTHOR: Pierre.Saramito@imag.fr
// DATE: 27 november 1998
namespace rheolef {
} // namespace rheolef
# include "rheolef/communicator.h"
# include "rheolef/dis_macros.h"
# include "rheolef/Vector.h"
namespace rheolef {
// [verbatim_distributor]
class distributor : public Vector<std::allocator<int>::size_type> {
public:
// typedefs:
typedef std::allocator<int>::size_type size_type;
typedef Vector<size_type> _base;
typedef _base::iterator iterator;
typedef _base::const_iterator const_iterator;
typedef int tag_type;
typedef communicator communicator_type;
// constants:
static const size_type decide = size_type(-1);
// allocators/deallocators:
distributor(
size_type dis_size = 0,
const communicator_type& c = communicator_type(),
size_type loc_size = decide);
distributor(const distributor&);
~distributor();
void resize(
size_type dis_size = 0,
const communicator_type& c = communicator_type(),
size_type loc_size = decide);
// accessors:
const communicator_type& comm() const;
size_type dis_size () const;
size_type process () const;
size_type n_process () const;
size_type find_owner (size_type dis_i) const;
size_type first_index (size_type iproc) const;
size_type last_index (size_type iproc) const;
size_type size (size_type iproc) const;
size_type first_index () const;
size_type last_index () const;
size_type size () const;
bool is_owned (size_type dis_i, size_type iproc) const;
// the same with ip=current process
bool is_owned (size_type dis_i) const;
static tag_type get_new_tag();
// comparators:
bool operator== (const distributor&) const;
bool operator!= (const distributor&) const;
// [verbatim_distributor]
// data:
protected:
communicator_type _comm;
// [verbatim_distributor_cont]
};
// [verbatim_distributor_cont]
// inline'd
inline
const distributor::communicator_type&
distributor::comm() const
{
return _comm;
}
inline
distributor::size_type
distributor::first_index(size_type j) const
{
return at(j);
}
inline
distributor::size_type
distributor::last_index(size_type j) const
{
return at(j+1);
}
inline
distributor::size_type
distributor::size(size_type j) const
{
return last_index(j) - first_index(j);
}
inline
distributor::size_type
distributor::n_process() const
{
#ifdef _RHEOLEF_HAVE_MPI
return _comm.size();
#else // _RHEOLEF_HAVE_MPI
return 1;
#endif // _RHEOLEF_HAVE_MPI
}
inline
distributor::size_type
distributor::process() const
{
#ifdef _RHEOLEF_HAVE_MPI
return _comm.rank();
#else // _RHEOLEF_HAVE_MPI
return 0;
#endif // _RHEOLEF_HAVE_MPI
}
inline
distributor::size_type
distributor::first_index() const
{
return first_index(process());
}
inline
distributor::size_type
distributor::last_index() const
{
return last_index(process());
}
inline
distributor::size_type
distributor::size() const
{
return size(process());
}
inline
distributor::size_type
distributor::dis_size() const
{
return at(n_process());
}
inline
bool
distributor::is_owned (size_type dis_i, size_type ip) const
{
return dis_i >= first_index(ip) && dis_i < last_index(ip);
}
inline
bool
distributor::is_owned (size_type dis_i) const
{
return is_owned (dis_i, process());
}
inline
bool
distributor::operator!= (const distributor& x) const
{
return !operator==(x);
}
inline
bool
distributor::operator== (const distributor& x) const
{
return (x.n_process() == n_process()) && (x.size() == size()) && (x.dis_size() == dis_size());
}
} // namespace rheolef
#endif // _RHEO_DISTRIBUTOR_H
communicator
see the communicator page for the full documentation
rheolef::distributor::last_index
size_type last_index() const
Definition distributor.h:202
rheolef::distributor::n_process
size_type n_process() const
number of processes
Definition distributor.h:176
rheolef::distributor::_base
Vector< size_type > _base
Definition distributor.h:75
rheolef::distributor::find_owner
size_type find_owner(size_type dis_i) const
find iproc associated to a global index dis_i: CPU=log(nproc)
Definition distributor.cc:106
rheolef::distributor::resize
void resize(size_type dis_size=0, const communicator_type &c=communicator_type(), size_type loc_size=decide)
Definition distributor.cc:30
rheolef::distributor::~distributor
~distributor()
Definition distributor.cc:102
rheolef::distributor::dis_size
size_type dis_size() const
global and local sizes
Definition distributor.h:214
rheolef::distributor::communicator_type
communicator communicator_type
Definition distributor.h:79
rheolef::distributor::size
size_type size(size_type iproc) const
Definition distributor.h:170
rheolef::distributor::get_new_tag
static tag_type get_new_tag()
returns a new tag
Definition distributor.cc:133
rheolef::distributor::iterator
_base::iterator iterator
Definition distributor.h:76
rheolef::distributor::process
size_type process() const
current process id
Definition distributor.h:186
rheolef::distributor::operator!=
bool operator!=(const distributor &) const
Definition distributor.h:232
rheolef::distributor::first_index
size_type first_index() const
global index range and local size owned by current process
Definition distributor.h:196
rheolef::distributor::operator==
bool operator==(const distributor &) const
Definition distributor.h:238
rheolef::distributor::const_iterator
_base::const_iterator const_iterator
Definition distributor.h:77
rheolef::distributor::_comm
communicator_type _comm
Definition distributor.h:144
rheolef::distributor::size
size_type size() const
Definition distributor.h:208
rheolef::distributor::is_owned
bool is_owned(size_type dis_i, size_type iproc) const
true when dis_i in [first_index(iproc):last_index(iproc)[
Definition distributor.h:220
rheolef::distributor::decide
static const size_type decide
Definition distributor.h:83
rheolef::distributor::tag_type
int tag_type
Definition distributor.h:78
rheolef::distributor::distributor
distributor(size_type dis_size=0, const communicator_type &c=communicator_type(), size_type loc_size=decide)
Definition distributor.cc:88
rheolef::distributor::size_type
std::allocator< int >::size_type size_type
Definition distributor.h:74
rheolef::distributor::comm
const communicator_type & comm() const
Definition distributor.h:152
rheolef
This file is part of Rheolef.
Definition compiler_eigen.h:39
rheolef::Vector< std::allocator< int >::size_type >::Vector
Vector(size_type n=0, const std::allocator< int >::size_type &value=std::allocator< int >::size_type())
Definition Vector.h:197
rheolef::Vector< size_type >::iterator
DATA::iterator iterator
Definition Vector.h:183
rheolef::Vector< size_type >::const_iterator
DATA::const_iterator const_iterator
Definition Vector.h:184
rheolef::Vector< std::allocator< int >::size_type >::at
const_reference at(size_type n) const
Definition Vector.h:283