fml  0.1-0
Fused Matrix Library
bcutils.hh
1 // This file is part of fml which is released under the Boost Software
2 // License, Version 1.0. See accompanying file LICENSE or copy at
3 // https://www.boost.org/LICENSE_1_0.txt
4 
5 #ifndef FML_MPI_INTERNALS_BCUTILS_H
6 #define FML_MPI_INTERNALS_BCUTILS_H
7 #pragma once
8 
9 
10 #include <cmath>
11 #include <stdlib.h>
12 
13 
14 namespace fml
15 {
16  namespace bcutils
17  {
18  enum desc_pos
19  {
20  DESC_DTYPE,
21  DESC_CTXT,
22  DESC_M,
23  DESC_N,
24  DESC_MB,
25  DESC_NB,
26  DESC_RSRC,
27  DESC_CSRC,
28  DESC_LLD
29  };
30 
31 
32 
33  enum blacs_pos
34  {
35  GRID_NPROCS,
36  GRID_NPROW,
37  GRID_NPCOL,
38  GRID_MYPROW,
39  GRID_MYPCOL
40  };
41 
42 
43 
44  inline void descinit(int *desc, const int ictxt, const int m, const int n, const int mb, const int nb, const int lld)
45  {
46  desc[DESC_DTYPE] = 1;
47  desc[DESC_CTXT] = ictxt;
48  desc[DESC_M] = m;
49  desc[DESC_N] = n;
50  desc[DESC_MB] = mb;
51  desc[DESC_NB] = nb;
52  desc[DESC_RSRC] = 0;
53  desc[DESC_CSRC] = 0;
54  desc[DESC_LLD] = (lld<1?1:lld);
55  }
56 
57 
58 
59  inline int numroc(int n, int nb, int iproc, int isrcproc, int nprocs)
60  {
61  int mydist = (nprocs+iproc-isrcproc) % nprocs;
62  int nblocks = n / nb;
63 
64  int ret = (nblocks/nprocs) * nb;
65 
66  int extrablks = nblocks % nprocs;
67  if (mydist < extrablks)
68  ret += nb;
69  else if (mydist == extrablks)
70  ret += (n%nb);
71 
72  return ret;
73  }
74 
75 
76 
77  inline int l2g(const int i, const int nb, const int nprocs, const int myproc)
78  {
79  return nprocs*nb*(i/nb) + (i%nb) + ((nprocs+myproc)%nprocs)*nb;
80  }
81 
82 
83 
84  inline int g2l(const int gi, const int nb, const int nprocs)
85  {
86  return nb * (gi/(nb*nprocs)) + (gi%nb);
87  }
88 
89 
90 
91  inline int g2p(const int gi, const int nb, const int nprocs)
92  {
93  return (gi/nb) % nprocs;
94  }
95  }
96 }
97 
98 
99 #endif
fml
Core namespace.
Definition: dimops.hh:10