45 ASSERT( ! ierr ,
"Can not get MPI rank.\n" );
47 ASSERT( ! ierr ,
"Can not get MPI size.\n" );
69 ASSERT( ! ierr ,
"Can not get MPI rank.\n" );
71 ASSERT( ! ierr ,
"Can not get MPI size.\n" );
75 for(
unsigned int i=0 ; i<
np(); i++)
starts[i+1]=
starts[i]+sizes[i];
83 :communicator(PETSC_COMM_WORLD),
88 ASSERT( ! ierr ,
"Can not get MPI rank.\n" );
90 ASSERT( ! ierr ,
"Can not get MPI size.\n" );
92 const PetscInt *petsc_starts;
93 VecGetOwnershipRanges(petsc_vector,&petsc_starts);
94 ASSERT( ! ierr ,
"Can not get vector ownership range.\n" );
97 for(
unsigned int i=0 ; i<=
np(); i++)
starts[i]=petsc_starts[i];
110 ASSERT( ! ierr ,
"Can not get MPI rank.\n" );
112 ASSERT( ! ierr ,
"Can not get MPI size.\n" );
113 ASSERT(
num_of_procs > 0,
"MPI size is not positive, possibly broken MPI communicator.\n");
116 unsigned int reminder, per_proc;
118 reminder=global_size %
np(); per_proc=global_size /
np();
122 for(
unsigned int i=0; i<
np(); i++)
129 for(
unsigned int i=1; i<=
np(); i++)
starts[i]=global_size;
132 ASSERT( 0 ,
"Cyclic distribution is not yet implemented.\n");
140 : communicator(distr.communicator)
158 ASSERT(idx <
size(),
"Index %d greater then distribution size %d.\n", idx,
size());
160 for(
unsigned int i=0; i<
np(); i++) {
163 ASSERT( 0 ,
"Can not find owner of index %d. \n", idx);
187 stream <<
"[" <<
myp() <<
"]" <<
"Distribution size: " <<
size() <<
" lsize: " <<
lsize() <<
" offset: " <<
begin() <<
" mpi_size: " <<
np() << endl;
188 for(
unsigned int i=0; i<
np();++i)
189 stream <<
"[" <<
myp() <<
"]" <<
"proc: " << i <<
" offset: " <<
begin(i) <<
" lsize: " <<
lsize(i) << endl;
unsigned int size() const
get global size
unsigned int get_proc(unsigned int idx) const
get processor of the given index
int my_proc
my proc number
unsigned int * starts
starts[i] index of the first index on the proc i; starts[n_procs]=size of whole array ...
unsigned int begin() const
Distribution(const unsigned int size, MPI_Comm comm)
int num_of_procs
number of procs
unsigned int lsize() const
const unsigned int * get_lsizes_array()
get local sizes array
void view(std::ostream &stream) const
distribution view
Global macros to enhance readability and debugging, general constants.
const MPI_Comm communicator
communicator
const unsigned int * get_starts_array() const
get local starts array
#define MPI_Allgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm)
unsigned int np() const
get num of processors
void * xmalloc(size_t size)
Memory allocation with checking.
unsigned int myp() const
get my processor
unsigned int * lsizes
local sizes
Support classes for parallel programing.
bool is_on_proc(unsigned int idx, unsigned int proc) const