1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
#ifndef HPC_MPI_GEMATRIX_H
#define HPC_MPI_GEMATRIX_H 1

#include <cassert>
#include <memory>
#include <type_traits>
#include <mpi.h>
#include <hpc/aux/ceildiv.h>
#include <hpc/aux/slices.h>
#include <hpc/matvec/gematrix.h>
#include <hpc/matvec/isgematrix.h>
#include <hpc/matvec/copy.h>
#include <hpc/mpi/fundamental.h>
#include <hpc/mpi/grid.h>

namespace hpc { namespace mpi {

template <typename T, typename I>
struct GeMatrix
{
    typedef T   ElementType;
    typedef I   Index;

    using StorageOrder = hpc::matvec::StorageOrder;

    GeMatrix(Index numRows, Index numCols, Grid grid)
        : numRows(numRows), numCols(numCols), grid(grid),
          buffer(getNumRows(grid.nodeRow), getNumCols(grid.nodeCol))
    {
    }

    Index
    getRowOffset(Index nodeRow) const
    {
        Index mb = (numRows+grid.numNodeRows-1)/grid.numNodeRows;
        return mb*nodeRow;
    }

    Index
    getColOffset(Index nodeCol) const
    {
        Index nb = (numCols+grid.numNodeCols-1)/grid.numNodeCols;
        return nb*nodeCol;
    }

    Index
    getNumRows(Index nodeRow) const
    {
        return numRows - getRowOffset(nodeRow);
    }

    Index
    getNumCols(Index nodeCol) const
    {
        return numCols - getColOffset(nodeCol);
    }

    Index                       numRows, numCols;
    Grid                        grid;
    hpc::matvec::GeMatrix<T,I>  buffer;
};

} } // namespaces mpi, hpc

#endif // HPC_MPI_GEMATRIX_H