Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
georgegito committed Sep 24, 2021
1 parent dc6e404 commit b015d13
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 131 deletions.
4 changes: 0 additions & 4 deletions include/blocking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ ret csr2bcsr(csr &M, bcsr &blM)
blM.n = M.n;

int numBlocksM = (blM.m / blM.b) * (blM.n / blM.b);
// int LL_bRowPtrSizeM = numBlocksM * (blM.b + 1);

// init Low-Level CSR
// blM.LL_bRowPtr = new int[LL_bRowPtrSizeM]();
blM.LL_bColInd = new int[M.nnz]();


Expand Down Expand Up @@ -135,10 +133,8 @@ ret csc2bcsc(csc &M, bcsc &blM)
blM.n = M.n;

int numBlocksM = (blM.m / blM.b) * (blM.n / blM.b);
// int LL_bColPtrSizeM = numBlocksM * (blM.b + 1);

// init Low-Level CSC
// blM.LL_bColPtr = new int[LL_bColPtrSizeM]();
blM.LL_bRowInd = new int[M.nnz]();

int numBlockRows = M.m / blM.b;
Expand Down
85 changes: 10 additions & 75 deletions include/distributed-block-bmm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <headers.hpp>
#include <mpi.h>

void distributedBlockBmm(int matIndF, int matIndA, int matIndB, bool isParallel, int argc, char **argv)
void distributedBlockBmm(int matIndF, int matIndA, int matIndB, bool isParallel, int b, int argc, char **argv)
{
struct timeval timer;
double tTotal = -1;
Expand All @@ -17,9 +17,6 @@ void distributedBlockBmm(int matIndF, int matIndA, int matIndB, bool isParallel,
double t6 = -1;

int numProcesses, rank;
int blockSizeF;
int blockSizeA;
int blockSizeB;

/* ----------------- initialize MPI and declare COO matrices ---------------- */

Expand All @@ -35,9 +32,9 @@ void distributedBlockBmm(int matIndF, int matIndA, int matIndB, bool isParallel,

/* ---------------------- distribute A and broadcast B ---------------------- */

t1 = distributeCooMatrix(numProcesses, rank, cooF, _cooF, matIndF, blockSizeF);
t2 = distributeCooMatrix(numProcesses, rank, cooA, _cooA, matIndA, blockSizeA);
t3 = broadcastCooMatrix(numProcesses, rank, cooB, matIndB, blockSizeB);
t1 = distributeCooMatrix(numProcesses, rank, cooF, _cooF, matIndF, b);
t2 = distributeCooMatrix(numProcesses, rank, cooA, _cooA, matIndA, b);
t3 = broadcastCooMatrix(numProcesses, rank, cooB, matIndB, b);

/* ------------------------ start timer in process 0 ------------------------ */

Expand Down Expand Up @@ -69,51 +66,31 @@ void distributedBlockBmm(int matIndF, int matIndA, int matIndB, bool isParallel,

coo2csr(csrA.rowPtr, csrA.colInd, _cooA.row, _cooA.col, _cooA.nnz, _cooA.m, 0);

// prt::csrMat(csrA);

csc cscB;
util::initCsc(cscB, cooB.m, cooB.n, cooB.nnz);

coo2csr(cscB.colPtr, cscB.rowInd, cooB.col, cooB.row, cooB.nnz, cooB.n, 0);

// prt::cscMat(cscB);

/* -------------------------- blocking of F Matrix -------------------------- */

// timer = util::tic();

bcsr bcsrF;

// blocking
csr2bcsr(csrF, bcsrF, blockSizeF);

// t = util::toc(timer);
// std::cout << "\nBlocking F in B-CSR completed\n" << "Blocking time = " << t << " seconds" << std::endl;

csr2bcsr(csrF, bcsrF, b);

/* -------------------------- blocking of A Matrix -------------------------- */

// timer = util::tic();

bcsr bcsrA;

// blocking
csr2bcsr(csrA, bcsrA, blockSizeA);

// t = util::toc(timer);
// std::cout << "\nBlocking A in B-CSR completed\n" << "Blocking time = " << t << " seconds" << std::endl;
csr2bcsr(csrA, bcsrA, b);

/* -------------------------- blocking of B Matrix -------------------------- */

// timer = util::tic();

bcsc bcscB;

// blocking
csc2bcsc(cscB, bcscB, blockSizeB);

// t = util::toc(timer);
// std::cout << "\nBlocking B in B-CSC completed\n" << "Blocking time = " << t << " seconds" << std::endl;
csc2bcsc(cscB, bcscB, b);

/* ------------------------ start timer in process 0 ------------------------ */

Expand All @@ -138,17 +115,13 @@ void distributedBlockBmm(int matIndF, int matIndA, int matIndB, bool isParallel,

/* --------------------------- sort result matrix --------------------------- */

// std::cout << "\nBlock-BMM completed\n" << "Block-BMM time = " << t << " seconds" << std::endl;

std::vector <std::pair <int, int>> _vecCooC;

for (auto &x : _cooC) {
_vecCooC.push_back(std::pair <int, int> (x.first, x.second));
}
std::sort(_vecCooC.begin(), _vecCooC.end());

// std::cout << "\nVector processing time = " << t << " seconds" << std::endl;

/* ------------------------ start timer in process 0 ------------------------ */

if (rank == 0)
Expand All @@ -164,12 +137,6 @@ void distributedBlockBmm(int matIndF, int matIndA, int matIndB, bool isParallel,

util::addCooRowOffsets(_vecCooC, _rowsC, _colsC, chunkStartingRow);
std::vector <std::pair <int, int>> bmmResultVec;

// if (rank == 0) {
// std::cout << "Process " << rank << " result: \n";
// prt::arr(_rowsC, selfSize);
// prt::arr(_colsC, selfSize);
// }

bmmResultGather(numProcesses, rank, selfSize, totalSize, _rowsC, _colsC, bmmResultRows,
bmmResultCols, bmmResultVec);
Expand Down Expand Up @@ -242,15 +209,8 @@ double distributeCooMatrix(int numProcesses, int rank, coo &M, coo &_M, int matI
if (rank == 0) {

/* ------------------------------- read matrix ------------------------------ */

// timer = util::tic();

read2coo(matInd, n, nnz, b, M);

// std::cout << "\nMatrix read successfully\nn = " << M.n << ", nnz = " << M.nnz << std::endl;
// t = util::toc(timer);
// std::cout << "\nReading time = " << t << std::endl;
// prt::cooMat(M);
read2coo(matInd, n, nnz, M);

/* ------------------- compute num of block rows per chunk ------------------ */

Expand All @@ -266,28 +226,18 @@ double distributeCooMatrix(int numProcesses, int rank, coo &M, coo &_M, int matI
bRowsPerChunk = numBlockRows / numProcesses;
rowsPerChunk = bRowsPerChunk * b;

// std::cout << "b = " << b << std::endl;
// std::cout << "numProcesses = " << numProcesses << std::endl;
// std::cout << "numBlockRows = " << numBlockRows << std::endl;
// std::cout << "bRowsPerChunk = " << bRowsPerChunk << std::endl;

/* -------------------- compute num of elements per chunk ------------------- */

for (int cnt = 0, elementCount = 0; cnt < M.nnz; cnt++, elementCount++) {

currentElement = M.row[cnt];
chunkInd = currentElement / rowsPerChunk;
// std::cout << "chunkId=" << chunkInd << std::endl;

chunkSizes[chunkInd]++;
chunkOffsets[chunkInd + 1] = chunkOffsets[chunkInd] + chunkSizes[chunkInd];
}

selfChunkSize = chunkSizes[0];

// prt::arr(chunkSizes, numProcesses);
// prt::arr(chunkDisplacements, numProcesses);

/* ---------- send array sizes to allocate memory on all processes ---------- */

for (int p = 1; p < numProcesses; p++)
Expand All @@ -306,8 +256,6 @@ double distributeCooMatrix(int numProcesses, int rank, coo &M, coo &_M, int matI
MPI_Bcast(&b, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(&rowsPerChunk, 1, MPI_INT, 0, MPI_COMM_WORLD);

// std::cout << "chunk " << rank << "\t_m = " << rowsPerChunk << "\tn = " << n << "\tb = " << b << std::endl;

/* ---------------------------- distribute matrix --------------------------- */

util::initCoo(_M, rowsPerChunk, n, selfChunkSize);
Expand All @@ -320,7 +268,6 @@ double distributeCooMatrix(int numProcesses, int rank, coo &M, coo &_M, int matI

if (rank == 0) {
t = util::toc(timer);
// std::cout << "Distribution of matrix time = " << t << std::endl;
util::delCoo(M);
return t;
}
Expand All @@ -342,14 +289,9 @@ double broadcastCooMatrix(int numProcesses, int rank, coo &M, int matInd, int &b

/* ------------------------------- read matrix ------------------------------ */

// timer = util::tic();
read2coo(matInd, n, nnz, M);

read2coo(matInd, n, nnz, b, M);

// std::cout << "\nMatrix read successfully\nn = " << M.n << ", nnz = " << M.nnz << std::endl;
// t = util::toc(timer);
// std::cout << "\nReading time = " << t << std::endl;
// prt::cooMat(M);
/* ------------------------ start timer in process 0 ------------------------ */

timer = util::tic();
}
Expand All @@ -365,9 +307,6 @@ double broadcastCooMatrix(int numProcesses, int rank, coo &M, int matInd, int &b
MPI_Bcast(M.col, M.nnz, MPI_INT, 0, MPI_COMM_WORLD);

t = util::toc(timer);
// std::cout << "Broadcast of matrix time = " << t << std::endl;

// prt::cooMat(M);

if (rank == 0) {
t = util::toc(timer);
Expand Down Expand Up @@ -416,8 +355,6 @@ void bmmResultGather( int numProcesses,

bmmResultRows = new int[totalSize];
bmmResultCols = new int[totalSize];
// prt::arr(resultSizes, numProcesses);
// prt::arr(resultOffsets, numProcesses);
}

MPI_Gatherv(rowsC, selfSize, MPI_INT, bmmResultRows, resultSizes, resultOffsets,
Expand All @@ -436,6 +373,4 @@ void bmmResultGather( int numProcesses,

delete[] resultSizes;
delete[] resultOffsets;
// delete[] bmmResultRows;
// delete[] bmmResultCols;
}
12 changes: 6 additions & 6 deletions include/headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ typedef struct

/* ----------------------------- read functions ----------------------------- */

void read2coo(int graphId, int &n, int &nnz, int &b, coo &M);
std::string read2csr(int graphId, int &n, int &nnz, int &b, csr &A);
std::string read2csc(int graphId, int &n, int &nnz, int &b, csc &B);
void read2coo(int graphId, int &n, int &nnz, coo &M);
std::string read2csr(int graphId, int &n, int &nnz, csr &A);
std::string read2csc(int graphId, int &n, int &nnz, csc &B);
void readMtxValues(std::string f, int &n, int &nnz);
void openMtxFile(std::string f, int *row, int *col, int &n, int &nnz);
int coo2csr(
Expand Down Expand Up @@ -192,12 +192,12 @@ void maskedBbm( bcsr &F,

void parallelMaskedBlockBmm(bcsr &F, bcsr &A, bcsc &B, std::multimap <int, int> &C);

void maskedBlockBmm(int matIndF, int matIndA, int matIndB, int argc, char **argv);
void parallelMaskedBlockBmm(int matIndF, int matIndA, int matIndB, int argc, char **argv);
void maskedBlockBmm(int matIndF, int matIndA, int matIndB, int b);
void parallelMaskedBlockBmm(int matIndF, int matIndA, int matIndB, int b);

/* ------------------------------ mpi functions ----------------------------- */

void distributedBlockBmm(int matIndF, int matIndA, int matIndB, bool parallel, int argc, char **argv);
void distributedBlockBmm(int matIndF, int matIndA, int matIndB, bool parallel, int b, int argc, char **argv);
double distributeCooMatrix(int numProcesses, int rank, coo &M, coo &_M, int matInd, int &b);
double broadcastCooMatrix(int numProcesses, int rank, coo &M, int matInd, int &b);
void bmmResultGather( int numProcesses,
Expand Down
9 changes: 4 additions & 5 deletions include/masked-block-bmm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/* ---------------------------- masked block-bmm ---------------------------- */

void maskedBlockBmm(int matIndF, int matIndA, int matIndB, int argc, char **argv)
void maskedBlockBmm(int matIndF, int matIndA, int matIndB, int b)
{
struct timeval timer;
double t = -1;
Expand All @@ -19,16 +19,15 @@ void maskedBlockBmm(int matIndF, int matIndA, int matIndB, int argc, char **argv
int nnzF;
int nnzA;
int nnzB;
int b;
csr F;
csr A;
csc B;

timer = util::tic();

read2csr(matIndF, nF, nnzF, b, F);
read2csr(matIndA, nA, nnzA, b, A);
read2csc(matIndB, nB, nnzB, b, B);
read2csr(matIndF, nF, nnzF, F);
read2csr(matIndA, nA, nnzA, A);
read2csc(matIndB, nB, nnzB, B);

t = util::toc(timer);
std::cout << "\nReading of F, A and B completed\n" << "Reading time = " << t << " seconds" << std::endl;
Expand Down
11 changes: 4 additions & 7 deletions include/parallel-masked-block-bmm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <headers.hpp>
#include <omp.h>

void parallelMaskedBlockBmm(int matIndF, int matIndA, int matIndB, int argc, char **argv)
void parallelMaskedBlockBmm(int matIndF, int matIndA, int matIndB, int b)
{
struct timeval timer;
double t = -1;
Expand All @@ -18,16 +18,15 @@ void parallelMaskedBlockBmm(int matIndF, int matIndA, int matIndB, int argc, cha
int nnzF;
int nnzA;
int nnzB;
int b;
csr F;
csr A;
csc B;

timer = util::tic();

read2csr(matIndF, nF, nnzF, b, F);
read2csr(matIndA, nA, nnzA, b, A);
read2csc(matIndB, nB, nnzB, b, B);
read2csr(matIndF, nF, nnzF, F);
read2csr(matIndA, nA, nnzA, A);
read2csc(matIndB, nB, nnzB, B);

t = util::toc(timer);
std::cout << "\nReading of F, A and B completed\n" << "Reading time = " << t << " seconds" << std::endl;
Expand Down Expand Up @@ -73,8 +72,6 @@ void parallelMaskedBlockBmm(int matIndF, int matIndA, int matIndB, int argc, cha
}
std::sort(vecC.begin(), vecC.end());

// prt::vec(vecC);

/* ------------------------------ check result ------------------------------ */

if (util::checkRes("C.mtx", vecC)) {
Expand Down
Loading

0 comments on commit b015d13

Please sign in to comment.