MpiHelper.h 2.85 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
27
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS

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

namespace AMDiS {

  namespace mpi {
    void globalAdd(double &value);

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

46
47
    void globalMin(double &value);

48
49
    void globalMin(int &value);

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

58
59
    void globalMax(int &value);

60
    template<typename T>
61
62
    void globalMax(T &value) 
    {
63
64
65
      WARNING("Unknown type for globalMax. Can not determine maximal value of all processors!\n");
    }
    
66
67
68
69
    inline void startRand()
    {
      srand(time(NULL) * (MPI::COMM_WORLD.Get_rank() + 1));
    }
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94

    /** \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);
    }
95
96
97
98
  }

}

99
#endif
100
101

#endif