Last active
April 4, 2018 21:26
-
-
Save Humberd/56cdb56a64f972e4756351a906d2fc27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct BoardColumn { | |
int iteration; | |
bool* column; | |
int columnIndex; | |
int leftColumnProcRank; | |
int rightColumnProcRank; | |
}; | |
std::vector<BoardColumn> bcs; // BoardColumnS | |
void Slave::iteration(int iteration) { | |
std::vector<MPI_Request*> requests; | |
std::vector<BoardColumn> newBcs; | |
/* Sending columns to neighbours */ | |
for (int i = 0; i < bcs.size(); ++i) { | |
/* When this column has left neighbour and its not me (this process) */ | |
if (bcs[i].leftColumnProcRank != NO_SIDE_COLUM_PROC_RANK && | |
bcs[i].leftColumnProcRank != rank) { | |
printf_debug("Slave %d - Iteration %d - Column %d has left neighbour Slave %d. Sending him my column...\n", | |
rank, iteration, bcs[i].columnIndex, bcs[i].leftColumnProcRank); | |
MPI_Request* reqs; | |
reqs = sendAsync(bcs[i], bcs[i].leftColumnProcRank, ITERATIONS_PHASE_TAG, MPI_COMM_WORLD, boardSize); | |
requests.push_back(&reqs[0]); | |
requests.push_back(&reqs[1]); | |
delete reqs; | |
} | |
/* When this column has right neighbour and its not me (this process) */ | |
if (bcs[i].rightColumnProcRank != NO_SIDE_COLUM_PROC_RANK && | |
bcs[i].rightColumnProcRank != rank) { | |
printf_debug("Slave %d - Iteration %d - Column %d has right neighbour Slave %d. Sending him my column...\n", | |
rank, iteration, bcs[i].columnIndex, bcs[i].rightColumnProcRank); | |
MPI_Request* reqs; | |
reqs = sendAsync(bcs[i], bcs[i].rightColumnProcRank, ITERATIONS_PHASE_TAG, MPI_COMM_WORLD, boardSize); | |
requests.push_back(&reqs[0]); | |
requests.push_back(&reqs[1]); | |
delete reqs; | |
} | |
} | |
bool *leftColumn, *rightColumn; | |
/* Receiving columns from neighbours */ | |
for (auto& bc : bcs) { | |
/* When I (this process) handles left column */ | |
if (bc.leftColumnProcRank == rank) { | |
printf_debug( | |
"Slave %d - Iteration %d - Column %d left neighbour is me. Getting it from my own resources.\n", | |
rank, iteration, bc.columnIndex); | |
leftColumn = getColumn(bc.columnIndex); | |
/* When there is no left column */ | |
} else if (bc.leftColumnProcRank == NO_SIDE_COLUM_PROC_RANK) { | |
printf_debug("Slave %d - Iteration %d - Column %d has no left neighbour. I'm virtualizing it.\n", | |
rank, iteration, bc.columnIndex); | |
leftColumn = virtualColumn; | |
} else { | |
printf_debug("Slave %d - Iteration %d - Column %d left column is in charge by Slave %d. Receiving...\n", | |
rank, iteration, bc.columnIndex, bc.leftColumnProcRank); | |
BoardColumn leftbc; | |
recv(leftbc, bc.leftColumnProcRank, ITERATIONS_PHASE_TAG, MPI_COMM_WORLD, boardSize); | |
leftColumn = leftbc.column; | |
} | |
/* When I (this process) handles right column */ | |
if (bc.rightColumnProcRank == rank) { | |
printf_debug( | |
"Slave %d - Iteration %d - Column %d right neighbour is me. Getting it from my own resources.\n", | |
rank, iteration, bc.columnIndex); | |
rightColumn = getColumn(bc.columnIndex); | |
/* When there is no right column */ | |
} else if (bc.rightColumnProcRank == NO_SIDE_COLUM_PROC_RANK) { | |
printf_debug("Slave %d - Iteration %d - Column %d has no right neighbour. I'm virtualizing it.\n", | |
rank, iteration, bc.columnIndex); | |
rightColumn = virtualColumn; | |
} else { | |
printf_debug("Slave %d - Iteration %d - Column %d right column is in charge by Slave %d. Receiving...\n", | |
rank, iteration, bc.columnIndex, bc.rightColumnProcRank); | |
BoardColumn rightbc; | |
recv(rightbc, bc.rightColumnProcRank, ITERATIONS_PHASE_TAG, MPI_COMM_WORLD, boardSize); | |
rightColumn = rightbc.column; | |
} | |
bool* newColumn = generateNewColumn(leftColumn, bc.column, rightColumn, boardSize); | |
BoardColumn newbc = bc; | |
newbc.column = newColumn; | |
newBcs.push_back(newbc); | |
} | |
/* Await all the remaining requests */ | |
MPI_Request** requestsArray = requests.data(); | |
MPI_Status* statusesArray = new MPI_Status[requests.size()]; | |
MPI_Waitall(requests.size(), *requestsArray, statusesArray); | |
for (auto& bc : bcs) { | |
delete[] bc.column; // <-- here the error is getting thrown | |
} | |
bcs.clear(); | |
bcs = newBcs; | |
newBcs.clear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment