Context.h 5.85 KB
Newer Older
Francois Gygi committed
1 2
////////////////////////////////////////////////////////////////////////////////
//
Francois Gygi committed
3 4 5 6 7 8 9 10 11 12 13 14
// Copyright (c) 2008 The Regents of the University of California
//
// This file is part of Qbox
//
// Qbox is distributed under the terms of the GNU General Public License 
// as published by the Free Software Foundation, either version 2 of 
// 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
// Context.h
//
////////////////////////////////////////////////////////////////////////////////
Francois Gygi committed
18
// $Id: Context.h,v 1.11 2008-08-13 06:39:42 fgygi Exp $
Francois Gygi committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

#ifndef CONTEXT_H
#define CONTEXT_H

#include <iosfwd>
#include <string>

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

class Context
{
  private:
35

Francois Gygi committed
36 37 38
  struct ContextImpl* pimpl_;

  public:
39

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

Francois Gygi committed
46 47 48 49 50 51 52 53 54
  // 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;
55

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

Francois Gygi committed
62 63 64
  // 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;
65 66

  void dsum(char scope, char topology,
Francois Gygi committed
67 68 69
            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;
70 71 72

  void dmax(char scope, char topology,
            int m, int n, double* a, int lda,
Francois Gygi committed
73
            int* ra, int* ca, int rcflag, int rdest, int cdest) const;
74
  void dmax(char scope, char topology,
Francois Gygi committed
75 76 77
            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;
78 79 80

  void dmin(char scope, char topology,
            int m, int n, double* a, int lda,
Francois Gygi committed
81
            int* ra, int* ca, int rcflag, int rdest, int cdest) const;
82
  void dmin(char scope, char topology,
Francois Gygi committed
83 84 85
            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;
86 87

  void dbcast_send(char scope, char topology,
Francois Gygi committed
88 89 90
                   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;
91 92

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

Francois Gygi committed
98 99 100
  // 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;
101
  void isum(char scope, char topology,
Francois Gygi committed
102 103 104
            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;
105 106 107

  void imax(char scope, char topology,
            int m, int n, int* a, int lda,
Francois Gygi committed
108
            int* ra, int* ca, int rcflag, int rdest, int cdest) const;
109
  void imax(char scope, char topology,
Francois Gygi committed
110 111 112
            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;
113 114 115

  void imin(char scope, char topology,
            int m, int n, int* a, int lda,
Francois Gygi committed
116
            int* ra, int* ca, int rcflag, int rdest, int cdest) const;
117
  void imin(char scope, char topology,
Francois Gygi committed
118 119 120
            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;
121 122

  void ibcast_send(char scope, char topology,
Francois Gygi committed
123 124 125
                   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;
126 127

  void ibcast_recv(char scope, char topology,
Francois Gygi committed
128
                   int m, int n, int* a, int lda, int rsrc, int csrc) const;
129
  void ibcast_recv(char scope, int m, int n,
Francois Gygi committed
130 131
                   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;
132

133 134 135
  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;
136

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

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

Francois Gygi committed
143 144 145 146
  // Constructors

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

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

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

Francois Gygi committed
156
  ~Context();
157

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

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

#endif