MaMiCo 1.2
Loading...
Searching...
No Matches
ZYXTopology.h
1// Copyright (C) 2015 Technische Universitaet Muenchen
2// This file is part of the Mamico project. For conditions of distribution
3// and use, please see the copyright notice in Mamico's main folder, or at
4// www5.in.tum.de/mamico
5#ifndef _MOLECULARDYNAMICS_COUPLING_PARALLELTOPOLOGY_ZYXTOPOLOGY_H_
6#define _MOLECULARDYNAMICS_COUPLING_PARALLELTOPOLOGY_ZYXTOPOLOGY_H_
7
8#include "coupling/CouplingMDDefinitions.h"
9#include "coupling/paralleltopology/ParallelTopology.h"
10
11namespace coupling {
12namespace paralleltopology {
13template <unsigned int dim> class ZYXTopology;
14}
15} // namespace coupling
16
32public:
35 : coupling::paralleltopology::ParallelTopology<dim>(), _numberProcesses(numberProcesses),
36 _divisionFactor4NumberProcesses(initDivisionFactor(numberProcesses)) {}
37
39 virtual ~ZYXTopology() {}
40
41 tarch::la::Vector<dim, unsigned int> getProcessCoordinates(unsigned int rank, unsigned int topologyOffset) const {
42 tarch::la::Vector<dim, unsigned int> processCoordinates(0);
43 unsigned int help = rank - topologyOffset;
44 for (unsigned int d = 0; d < dim; d++) {
45 processCoordinates[d] = help / _divisionFactor4NumberProcesses[d];
46 help = help - processCoordinates[d] * _divisionFactor4NumberProcesses[d];
47 }
48#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
49 std::cout << "Rank=" << rank << " corresponds to process coordinates=" << processCoordinates << std::endl;
50#endif
51 return processCoordinates;
52 }
53
56 unsigned int getRank(tarch::la::Vector<dim, unsigned int> processCoordinates, unsigned int topologyOffset) const {
57 unsigned int rank = processCoordinates[0];
58 for (unsigned int d = 1; d < dim; d++) {
59 rank = rank * _numberProcesses[d] + processCoordinates[d];
60 }
61 return rank + topologyOffset;
62 }
63
64private:
69 for (int d = dim - 2; d > -1; d--) {
70 div[d] = div[d + 1] * numberProcesses[d + 1];
71 }
72 return div;
73 }
74
75 /* number of processes */
76 const tarch::la::Vector<dim, unsigned int> _numberProcesses;
77 /* division factor */
78 const tarch::la::Vector<dim, unsigned int> _divisionFactor4NumberProcesses;
79};
80#endif // _MOLECULARDYNAMICS_COUPLING_PARALLELTOPOLOGY_ZYXTOPOLOGY_H_
This class performs the conversion rank <-> process coordinates.
Definition ParallelTopology.h:27
The ZYXTopology orders the ranks in z-y-x manner.
Definition ZYXTopology.h:31
tarch::la::Vector< dim, unsigned int > getProcessCoordinates(unsigned int rank, unsigned int topologyOffset) const
converts rank into process coordinates.
Definition ZYXTopology.h:41
ZYXTopology(tarch::la::Vector< dim, unsigned int > numberProcesses)
Definition ZYXTopology.h:34
tarch::la::Vector< dim, unsigned int > initDivisionFactor(tarch::la::Vector< dim, unsigned int > numberProcesses) const
Definition ZYXTopology.h:67
unsigned int getRank(tarch::la::Vector< dim, unsigned int > processCoordinates, unsigned int topologyOffset) const
Definition ZYXTopology.h:56
virtual ~ZYXTopology()
Definition ZYXTopology.h:39
Definition Vector.h:24
Definition ParallelTopology.h:12
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15