MpiHelper.h 2.73 KB
Newer Older
1
2
3
4
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
5
// ==  http://www.amdis-fem.org                                              ==
6
7
// ==                                                                        ==
// ============================================================================
8
9
10
11
12
13
14
15
16
17
18
19
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


20
21
22
23
24
25

/** \file MpiHelper.h */

#ifndef AMDIS_MPIHELPER_H
#define AMDIS_MPIHELPER_H

26
#include <mpi.h>
27
28
#include <time.h>
#include <stdlib.h>
29
#include "Global.h"
30
31
32
33
34
35

namespace AMDiS {

  namespace mpi {
    void globalAdd(double &value);

36
    void globalAdd(int &value);
37
38
    
    template<typename T>
39
40
    void globalAdd(T &value) 
    {
41
42
      WARNING("Unknown type for globalAdd. Can not sum up the values of all processors!\n");
    }
43

44
45
    void globalMin(double &value);

46
47
    void globalMin(int &value);

48
    template<typename T>
49
50
    void globalMin(T &value) 
    {
51
52
53
      WARNING("Unknown type for globalMin. Can not determine minimal value of all processors!\n");
    }
    
54
    void globalMax(double &value);
55

56
57
    void globalMax(int &value);

58
    template<typename T>
59
60
    void globalMax(T &value) 
    {
61
62
63
      WARNING("Unknown type for globalMax. Can not determine maximal value of all processors!\n");
    }
    
64
    void startRand();
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

    /** \brief
     * In many situations a rank computes a number of local DOFs. Then all
     * ranks want to know the number of global DOFs and the starting 
     * displacment number of the DOF numbering in each rank.
     *
     * \param[in]   mpiComm        The MPI communicator.
     * \param[in]   nRankDofs      The number of local DOFs.
     * \param[out]  rStartDofs     Displacment of the DOF numbering. On rank n
     *                             this is the sum of all local DOF numbers in
     *                             ranks 0 to n - 1.
     * \param[out]  nOverallDofs   Global sum of nRankDofs. Is equal on all
     *                             ranks.
     */
    inline void getDofNumbering(MPI::Intracomm& mpiComm,
				int nRankDofs, 
				int& rStartDofs, 
				int& nOverallDofs)
    {
      rStartDofs = 0;
      nOverallDofs = 0;
      mpiComm.Scan(&nRankDofs, &rStartDofs, 1, MPI_INT, MPI_SUM);
      rStartDofs -= nRankDofs;
      mpiComm.Allreduce(&nRankDofs, &nOverallDofs, 1, MPI_INT, MPI_SUM);
    }
90
91
92
93
  }

}

94
#endif