MpiHelper.cc 1.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// 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.


13
#include <mpi.h>
14
15
16
17
18
19
20
21
22
23
24
#include "MpiHelper.h"

namespace AMDiS {

  namespace mpi {

    void globalAdd(double &value)
    {
      double valCopy = value;
      MPI::COMM_WORLD.Allreduce(&valCopy, &value, 1, MPI_DOUBLE, MPI_SUM);
    }
25
26
27
28
29
30

    void globalAdd(int &value)
    {
      int valCopy = value;
      MPI::COMM_WORLD.Allreduce(&valCopy, &value, 1, MPI_INT, MPI_SUM);
    }
31
32
33
34
35
36
    
    void globalMin(double &value)
    {
      double valCopy = value;
      MPI::COMM_WORLD.Allreduce(&valCopy, &value, 1, MPI_DOUBLE, MPI_MIN);
    }
37
38
39
40
41
42

    void globalMin(int &value)
    {
      int valCopy = value;
      MPI::COMM_WORLD.Allreduce(&valCopy, &value, 1, MPI_INT, MPI_MIN);
    }
43
44
45
46
47
48
49
    
    void globalMax(double &value)
    {
      double valCopy = value;
      MPI::COMM_WORLD.Allreduce(&valCopy, &value, 1, MPI_DOUBLE, MPI_MAX);
    }

50
51
52
53
54
55
    void globalMax(int &value)
    {
      int valCopy = value;
      MPI::COMM_WORLD.Allreduce(&valCopy, &value, 1, MPI_INT, MPI_MAX);
    }

56
57
58
59
    void startRand()
    {
      srand(time(NULL) * (MPI::COMM_WORLD.Get_rank() + 1));
    }
60
61
  }
}
62