Saras
Finite   Difference   Solver   for   Fluid   Dynamics   Simulations
parallel.h
Go to the documentation of this file.
1/********************************************************************************************************************************************
2 * Saras
3 *
4 * Copyright (C) 2019, Mahendra K. Verma
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 ********************************************************************************************************************************************
31 */
43#ifndef PARALLEL_H
44#define PARALLEL_H
45
46#include <blitz/array.h>
47#include <mpi.h>
48
49#include "parser.h"
50
51class parallel {
52 private:
53 inline void assignRanks();
54 void getNeighbours();
55 void createComms();
56
57 public:
58 // ALL THE INTEGERS USED BELOW ARE POSITIVE. STILL IT IS BETTER TO USE int INSTEAD OF unsigned int
60 int rank;
61
63 int nProc;
64
67 const int npX, npY;
69
72 MPI_Comm MPI_ROW_COMM, MPI_COL_COMM;
74
78 int xRank, yRank;
80
82 blitz::Array<int, 1> faceRanks;
83
85 blitz::Array<int, 1> edgeRanks;
86
87 parallel(const parser &iDat);
88
104 static inline int pmod(int a, int b) {return (a % b + b) % b;};
105
121 inline int findRank(int xR, int yR) {return pmod(yR, npY)*npX + pmod(xR, npX);};
122};
123
137#endif
Class for all the global variables and functions related to parallelization.
Definition: parallel.h:51
int xRank
xRank and yRank indicates the rank in terms of sub-domain divisions along the X and Y directions resp...
Definition: parallel.h:78
blitz::Array< int, 1 > edgeRanks
Array of ranks of the 4 neighbouring sub-domains across edges - Left-Front, Left-Back,...
Definition: parallel.h:85
const int npX
npX and npY indicates the number of sub-domain divisions along the X and Y directions respectively
Definition: parallel.h:67
int rank
The MPI rank of each sub-domain.
Definition: parallel.h:60
int findRank(int xR, int yR)
Function to calculate the global rank of a sub-domain using its xRank and yRank.
Definition: parallel.h:121
MPI_Comm MPI_ROW_COMM
Row and column communicators.
Definition: parallel.h:72
blitz::Array< int, 1 > faceRanks
Array of ranks of the 4 neighbouring sub-domains across faces - Left, Right, Front,...
Definition: parallel.h:82
static int pmod(int a, int b)
Function to calculate the positive modulus of two numbers.
Definition: parallel.h:104
parallel(const parser &iDat)
Constructor of the parallel class.
Definition: parallel.cc:57
int nProc
The total number of cores available for computation.
Definition: parallel.h:63
Contains all the global variables set by the user through the yaml file.
Definition: parser.h:63
Class declaration of parser.