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_PARALLELTOPOLOGYFACTORY_H_
6 : #define _MOLECULARDYNAMICS_COUPLING_PARALLELTOPOLOGY_PARALLELTOPOLOGYFACTORY_H_
7 :
8 : #include "coupling/paralleltopology/ParallelTopology.h"
9 : #include "coupling/paralleltopology/XYZTopology.h"
10 : #include "coupling/paralleltopology/ZYXTopology.h"
11 :
12 : namespace coupling {
13 : namespace paralleltopology {
14 : class ParallelTopologyFactory;
15 : /** parallel topology types that are supported.
16 : * @enum ParallelTopologyType specifies the ordering of the MPI processes
17 : *(for domain decomposition). As an example: assuming ParallelTopologyType = XYZ
18 : *and there is a cubic domain, splitted into 8 sub-domains (2 sub-domains in
19 : *each dimension). Then the ordring of the MPI processes is: Rank=0 for
20 : *x=0,y=0,z=0. Rank=1 for x=0,y=0,z=1. Rank=2 for x=0,y=1,z=0. Rank=3 for
21 : *x=0,1=0,z=1. Rank=4 for x=1,y=0,z=0. Rank=5 for x=1,y=0,z=1. Rank=6 for
22 : *x=1,y=1,z=0. Rank=7 for x=1,y=1,z=1.
23 : */
24 : enum ParallelTopologyType {
25 : UNDEFINED = 0 /**< gherghere gher */
26 : ,
27 : XYZ = 1 /**< the XYZTopology orders the ranks in x-y-z manner, i.e. we obtain
28 : the rank from process coordinates (x,y,z) by z*nx*ny + y*nx + x=x +
29 : nx*(y+ny*z)*/
30 : ,
31 : ZYX = 2 /**< the ZYXTopology orders the ranks in z-y-x manner, i.e. we obtain
32 : the rank from process coordinates (z,y,x) by x*nz*ny + y*nz + z=z +
33 : nz*(y+ny*x)*/
34 : };
35 : } // namespace paralleltopology
36 : } // namespace coupling
37 : /** This class creates the parallel topology from a given topology type and a
38 : *number of processes (typically read from a configuration). assuming
39 : *ParallelTopologyType = XYZ and there is a cubic domain, splitted into 8
40 : *sub-domains (2 sub-domains in each dimension). Then the ordring of the MPI
41 : *processes is: Rank=0 for x=0,y=0,z=0. Rank=1 for x=0,y=0,z=1. Rank=2 for
42 : *x=0,y=1,z=0. Rank=3 for x=0,1=0,z=1. Rank=4 for x=1,y=0,z=0. Rank=5 for
43 : *x=1,y=0,z=1. Rank=6 for x=1,y=1,z=0. Rank=7 for x=1,y=1,z=1.
44 : * @brief creates the parallel topology from a given topology type and a
45 : *number of processes
46 : * @author Philipp Neumann
47 : */
48 : class coupling::paralleltopology::ParallelTopologyFactory {
49 : public:
50 : /** @brief This template function takes ParallelTopologyType and the number of
51 : *processes as inputs and returns a pointer to the created parallel topology.
52 : * @tparam dim Number of dimensions; it can be 1, 2 or 3
53 : * @param type ParallelTopologyType (rdering of the MPI processes)
54 : * @param numberProcesses number of processes
55 : */
56 : template <unsigned int dim>
57 788 : static coupling::paralleltopology::ParallelTopology<dim>* getParallelTopology(coupling::paralleltopology::ParallelTopologyType type,
58 : tarch::la::Vector<dim, unsigned int> numberProcesses) {
59 780 : if (type == XYZ) {
60 1544 : return new coupling::paralleltopology::XYZTopology<dim>(numberProcesses);
61 8 : } else if (type == ZYX) {
62 16 : return new coupling::paralleltopology::ZYXTopology<dim>(numberProcesses);
63 : } else {
64 : return NULL;
65 : }
66 : }
67 : };
68 : #endif
|