Context.h 5.79 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
Francois Gygi committed
7 8
// Qbox is distributed under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 2 of
Francois Gygi committed
9 10 11 12 13 14
// the License, or (at your option) any later version.
// See the file COPYING in the root directory of this distribution
// or <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
15 16 17 18 19 20 21 22
// Context.h
//
////////////////////////////////////////////////////////////////////////////////

#ifndef CONTEXT_H
#define CONTEXT_H

#include <iosfwd>
23
#include <string>
Francois Gygi committed
24 25 26 27 28 29 30 31 32 33

#if USE_MPI
#include <mpi.h>
#else
typedef int MPI_Comm;
#endif

class Context
{
  private:
34

Francois Gygi committed
35 36 37
  struct ContextImpl* pimpl_;

  public:
38

Francois Gygi committed
39 40 41 42 43
  int ictxt() const;
  int myrow() const;
  int mycol() const;
  int nprow() const;
  int npcol() const;
44

Francois Gygi committed
45 46 47 48 49 50 51 52 53
  // number of processes in the context
  // returns -1 if current process is not part of this context
  int size() const;
  // position of current process in row-major order
  // returns -1 if current process is not part of this context
  int myproc() const;
  int mype() const;
  // process id of process (irow,icol)
  int pmap(int irow, int icol) const;
54

Francois Gygi committed
55 56 57 58 59
  bool onpe0(void) const;
  bool active(void) const;
  void abort(int ierr) const;
  void barrier(void) const;
  void barrier(char scope) const;
60

Francois Gygi committed
61 62 63
  // double communications
  void dsend(int m, int n, double* a, int lda, int rdest, int cdest) const;
  void drecv(int m, int n, double* a, int lda, int rsrc, int csrc) const;
64 65

  void dsum(char scope, char topology,
Francois Gygi committed
66 67 68
            int m, int n, double* a, int lda, int rdest, int cdest) const;
  void dsum(char scope, int m, int n, double* a, int lda) const;
  void dsum(int m, int n, double* a, int lda) const;
69 70 71

  void dmax(char scope, char topology,
            int m, int n, double* a, int lda,
Francois Gygi committed
72
            int* ra, int* ca, int rcflag, int rdest, int cdest) const;
73
  void dmax(char scope, char topology,
Francois Gygi committed
74 75 76
            int m, int n, double* a, int lda, int rdest, int cdest) const;
  void dmax(char scope, int m, int n, double* a, int lda) const;
  void dmax(int m, int n, double* a, int lda) const;
77 78 79

  void dmin(char scope, char topology,
            int m, int n, double* a, int lda,
Francois Gygi committed
80
            int* ra, int* ca, int rcflag, int rdest, int cdest) const;
81
  void dmin(char scope, char topology,
Francois Gygi committed
82 83 84
            int m, int n, double* a, int lda, int rdest, int cdest) const;
  void dmin(char scope, int m, int n, double* a, int lda) const;
  void dmin(int m, int n, double* a, int lda) const;
85 86

  void dbcast_send(char scope, char topology,
Francois Gygi committed
87 88 89
                   int m, int n, double* a, int lda) const;
  void dbcast_send(char scope, int m, int n, double* a, int lda) const;
  void dbcast_send(int m, int n, double* a, int lda) const;
90 91

  void dbcast_recv(char scope, char topology,
Francois Gygi committed
92
               int m, int n, double* a, int lda, int rsrc, int csrc) const;
93
  void dbcast_recv(char scope, int m, int n, double* a,
Francois Gygi committed
94 95
                   int lda,int rsrc, int csrc) const;
  void dbcast_recv(int m, int n, double* a, int lda,int rsrc, int csrc) const;
96

Francois Gygi committed
97 98 99
  // integer communications
  void isend(int m, int n, int* a, int lda, int rdest, int cdest) const;
  void irecv(int m, int n, int* a, int lda, int rsrc, int csrc) const;
100
  void isum(char scope, char topology,
Francois Gygi committed
101 102 103
            int m, int n, int* a, int lda, int rdest, int cdest) const;
  void isum(char scope, int m, int n, int* a, int lda) const;
  void isum(int m, int n, int* a, int lda) const;
104 105 106

  void imax(char scope, char topology,
            int m, int n, int* a, int lda,
Francois Gygi committed
107
            int* ra, int* ca, int rcflag, int rdest, int cdest) const;
108
  void imax(char scope, char topology,
Francois Gygi committed
109 110 111
            int m, int n, int* a, int lda, int rdest, int cdest) const;
  void imax(char scope, int m, int n, int* a, int lda) const;
  void imax(int m, int n, int* a, int lda) const;
112 113 114

  void imin(char scope, char topology,
            int m, int n, int* a, int lda,
Francois Gygi committed
115
            int* ra, int* ca, int rcflag, int rdest, int cdest) const;
116
  void imin(char scope, char topology,
Francois Gygi committed
117 118 119
            int m, int n, int* a, int lda, int rdest, int cdest) const;
  void imin(char scope, int m, int n, int* a, int lda) const;
  void imin(int m, int n, int* a, int lda) const;
120 121

  void ibcast_send(char scope, char topology,
Francois Gygi committed
122 123 124
                   int m, int n, int* a, int lda) const;
  void ibcast_send(char scope, int m, int n, int* a, int lda) const;
  void ibcast_send(int m, int n, int* a, int lda) const;
125 126

  void ibcast_recv(char scope, char topology,
Francois Gygi committed
127
                   int m, int n, int* a, int lda, int rsrc, int csrc) const;
128
  void ibcast_recv(char scope, int m, int n,
Francois Gygi committed
129 130
                   int* a, int lda,int rsrc, int csrc) const;
  void ibcast_recv(int m, int n, int* a, int lda,int rsrc, int csrc) const;
131

132 133 134
  void string_send(std::string& s, int rdest, int cdest) const;
  void string_recv(std::string& s, int rsrc, int csrc) const;
  void string_bcast(std::string& s, int isrc) const;
135

Francois Gygi committed
136
  bool operator==(const Context& ctxt) const;
137

Francois Gygi committed
138 139 140
  // MPI communicator for this context. Returns MPI_COMM_NULL if
  // this process is not part of the context
  MPI_Comm comm(void) const;
141

Francois Gygi committed
142 143 144 145
  // Constructors

  // default global context: construct a single-row global Context
  explicit Context();
146

147 148
  // global Context of size nprow * npcol with column major order
  explicit Context(int nprow, int npcol);
149

Francois Gygi committed
150
  // construct a Context of size nprow*npcol from the processes
151 152
  // in context ctxt starting at process (irstart,icstart)
  explicit Context(const Context &ctxt, int nprow, int npcol,
153
    int irstart, int icstart);
154

Francois Gygi committed
155
  ~Context();
156

Francois Gygi committed
157 158
  Context(const Context& ctxt);
  Context& operator=(const Context& rhs);
159

160
  void print(std::ostream& os) const;
Francois Gygi committed
161
};
162
std::ostream& operator << ( std::ostream& os, const Context& ctxt );
Francois Gygi committed
163 164

#endif