LCOV - code coverage report
Current view: top level - coupling/paralleltopology - XYZTopology.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 11 100.0 %
Date: 2025-06-25 11:26:37 Functions: 6 10 60.0 %

          Line data    Source code
       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_XYZTOPOLOGY_H_
       6             : #define _MOLECULARDYNAMICS_COUPLING_PARALLELTOPOLOGY_XYZTOPOLOGY_H_
       7             : 
       8             : #include "coupling/CouplingMDDefinitions.h"
       9             : #include "coupling/paralleltopology/ParallelTopology.h"
      10             : 
      11             : namespace coupling {
      12             : namespace paralleltopology {
      13             : template <unsigned int dim> class XYZTopology;
      14             : }
      15             : } // namespace coupling
      16             : 
      17             : /** the XYZTopology orders the ranks in x-y-z manner, i.e. we obtain the rank
      18             :  * from process coordinates (x,y,z) by z*nx*ny + y*nx + x=x + nx*(y+ny*z), where
      19             :  * nx,ny,nz are the numbers of processes in x,y,z-direction. topologyOffset can
      20             :  * be used to shift the whole topology by an offset of ranks. Derived class from
      21             :  * the class ParallelTopology. E.g. assuming ParallelTopologyType = XYZ and there
      22             :  * is a cubic domain, splitted into 8 sub-domains (2 sub-domains in each
      23             :  * dimension). Then the ordering of the MPI processes is: Rank=0 for x=0,y=0,z=0.
      24             :  * Rank=1 for x=1,y=0,z=0. Rank=2 for x=0,y=1,z=0. Rank=3 for x=1,y=1,z=0. Rank=4
      25             :  * for x=0,y=0,z=1. Rank=5 for x=1,y=0,z=1. Rank=6 for x=0,y=1,z=1. Rank=7 for
      26             :  * x=1,y=1,z=1.
      27             :  * @brief The XYZTopology orders the ranks in x-y-z manner.
      28             :  * @tparam dim Number of dimensions; it can be 1, 2 or 3
      29             :  * @author Philipp Neumann
      30             :  * @todo Philipp could you please take a look on this class
      31             :  */
      32             : template <unsigned int dim> class coupling::paralleltopology::XYZTopology : public coupling::paralleltopology::ParallelTopology<dim> {
      33             : public:
      34             :   /** Constructor */
      35         788 :   XYZTopology(tarch::la::Vector<dim, unsigned int> numberProcesses)
      36        1576 :       : coupling::paralleltopology::ParallelTopology<dim>(), _numberProcesses(numberProcesses),
      37        1576 :         _divisionFactor4NumberProcesses(coupling::initDivisionFactor<dim>(numberProcesses)) {}
      38             : 
      39             :   /** Destructor */
      40          24 :   virtual ~XYZTopology() {}
      41             : 
      42         908 :   tarch::la::Vector<dim, unsigned int> getProcessCoordinates(unsigned int rank, unsigned int topologyOffset) const {
      43             : #if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
      44             :     std::cout << "Rank=" << rank
      45             :               << " corresponds to process coordinates=" << coupling::getVectorCellIndex<dim>(rank - topologyOffset, _divisionFactor4NumberProcesses)
      46             :               << std::endl;
      47             : #endif
      48         908 :     return coupling::getVectorCellIndex<dim>(rank - topologyOffset, _divisionFactor4NumberProcesses);
      49             :   }
      50             : 
      51         260 :   unsigned int getRank(tarch::la::Vector<dim, unsigned int> processCoordinates, unsigned int topologyOffset) const {
      52         260 :     unsigned int index = processCoordinates[dim - 1];
      53         756 :     for (int d = dim - 2; d > -1; d--) {
      54         496 :       index = _numberProcesses[d] * index + processCoordinates[d];
      55             :     }
      56         260 :     return index + topologyOffset;
      57             :   }
      58             : 
      59             : private:
      60             :   /* number of processes */
      61             :   const tarch::la::Vector<dim, unsigned int> _numberProcesses;
      62             :   /* division factor for number of processes */
      63             :   const tarch::la::Vector<dim, unsigned int> _divisionFactor4NumberProcesses;
      64             : };
      65             : 
      66             : #endif // _MOLECULARDYNAMICS_COUPLING_PARALLELTOPOLOGY_XYZTOPOLOGY_H_

Generated by: LCOV version 1.14