|
|
|
@ -1,11 +1,7 @@ |
|
|
|
|
#include "common.h" |
|
|
|
|
|
|
|
|
|
#define INPUTFILE "assignment2.in" |
|
|
|
|
#define INPUTFILE "assignment3.in1" |
|
|
|
|
|
|
|
|
|
// TODO: define custom structure for this probably
|
|
|
|
|
#define CODE_SIZE 0 |
|
|
|
|
#define CODE_INDEX 1 |
|
|
|
|
#define NUM_CODES 2 |
|
|
|
|
|
|
|
|
|
int transpose_index(int index, int rows, int cols); |
|
|
|
|
|
|
|
|
@ -28,33 +24,9 @@ int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
|
|
arrIndicesTransp = my_malloc(numCount * sizeof(int)); |
|
|
|
|
|
|
|
|
|
int numBlockIndex = 0; |
|
|
|
|
int numRemainder = numCount % numProcesses; |
|
|
|
|
spread_evenly(numProcesses, numCount, &arrBlockIndices, &arrBlockSizes); |
|
|
|
|
|
|
|
|
|
arrBlockIndices = my_malloc(numProcesses * sizeof(int)); |
|
|
|
|
arrBlockSizes = my_malloc(numProcesses * sizeof(int)); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < numProcesses; i++) { |
|
|
|
|
arrBlockSizes[i] = numCount / numProcesses; |
|
|
|
|
if (numRemainder > 0) { |
|
|
|
|
arrBlockSizes[i]++; |
|
|
|
|
numRemainder--; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
arrBlockIndices[i] = numBlockIndex; |
|
|
|
|
numBlockIndex += arrBlockSizes[i]; |
|
|
|
|
|
|
|
|
|
int arrTransp[NUM_CODES]; |
|
|
|
|
arrTransp[CODE_SIZE] = arrBlockSizes[i];
|
|
|
|
|
arrTransp[CODE_INDEX] = arrBlockIndices[i];
|
|
|
|
|
// Send every process starting index of 1D represented matrix and number of
|
|
|
|
|
// succeding indices to calculate transposition
|
|
|
|
|
MPI_Send(arrTransp, NUM_CODES, MPI_INT, i, NUM_CODES, MPI_COMM_WORLD);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//for (int i = 0; i < numProcesses; i++) {
|
|
|
|
|
//printf("size[%d] = %d\tindex[%d] = %d\n", i, arrBlockSizes[i], i, arrBlockIndices[i]);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -62,21 +34,21 @@ int main(int argc, char *argv[]) { |
|
|
|
|
MPI_Bcast(&numCols, 1, MPI_INT, 0, MPI_COMM_WORLD); |
|
|
|
|
//printf("size %2d, index %2d, buffer %2d, rank %d\n", packet[0], packet[1], packet[CODE_COUNT], numRank);
|
|
|
|
|
|
|
|
|
|
int arrTransp[NUM_CODES]; |
|
|
|
|
MPI_Recv(arrTransp, NUM_CODES, MPI_INT, 0, NUM_CODES, MPI_COMM_WORLD, &status); |
|
|
|
|
int arrBlockData[NUM_CODES]; |
|
|
|
|
MPI_Recv(arrBlockData, NUM_CODES, MPI_INT, 0, 1, MPI_COMM_WORLD, &status); |
|
|
|
|
|
|
|
|
|
//We can calculate numRows * numCols = numCount
|
|
|
|
|
int numRows = numCount / numCols; |
|
|
|
|
int *arrIndicesSub = my_malloc(numCount * sizeof(int)); |
|
|
|
|
//for (int i = arrTransp[CODE_INDEX]; i < (arrTransp[CODE_SIZE] + arrTransp[CODE_INDEX]); i++) {
|
|
|
|
|
for (int i = 0; i < arrTransp[CODE_SIZE]; i++) { |
|
|
|
|
//for (int i = arrBlockData[CODE_INDEX]; i < (arrBlockData[CODE_SIZE] + arrBlockData[CODE_INDEX]); i++) {
|
|
|
|
|
for (int i = 0; i < arrBlockData[CODE_SIZE]; i++) { |
|
|
|
|
// Only the indices are transposed in parallel
|
|
|
|
|
int index = transpose_index(i + arrTransp[CODE_INDEX], numRows, numCols); |
|
|
|
|
int index = transpose_index(i + arrBlockData[CODE_INDEX], numRows, numCols); |
|
|
|
|
arrIndicesSub[i] = index; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//if (numRank == 0)
|
|
|
|
|
MPI_Gatherv(arrIndicesSub, arrTransp[CODE_SIZE], MPI_INT, arrIndicesTransp, arrBlockSizes, arrBlockIndices,
|
|
|
|
|
MPI_Gatherv(arrIndicesSub, arrBlockData[CODE_SIZE], MPI_INT, arrIndicesTransp, arrBlockSizes, arrBlockIndices,
|
|
|
|
|
MPI_INT, 0, MPI_COMM_WORLD); |
|
|
|
|
|
|
|
|
|
//if (numRank == 0 ) {
|
|
|
|
@ -109,3 +81,33 @@ int transpose_index(int index, int rows, int cols) { |
|
|
|
|
return (index / rows) + cols * (index % rows); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//int numBlockIndex = 0;
|
|
|
|
|
//int numRemainder = numCount % numProcesses;
|
|
|
|
|
|
|
|
|
|
//arrBlockIndices = my_malloc(numProcesses * sizeof(int));
|
|
|
|
|
//arrBlockSizes = my_malloc(numProcesses * sizeof(int));
|
|
|
|
|
|
|
|
|
|
//for (int i = 0; i < numProcesses; i++) {
|
|
|
|
|
//arrBlockSizes[i] = numCount / numProcesses;
|
|
|
|
|
//if (numRemainder > 0) {
|
|
|
|
|
//arrBlockSizes[i]++;
|
|
|
|
|
//numRemainder--;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//arrBlockIndices[i] = numBlockIndex;
|
|
|
|
|
//numBlockIndex += arrBlockSizes[i];
|
|
|
|
|
//printf("size[%d] = %d\tindex[%d] = %d\n", i, arrBlockSizes[i], i, arrBlockIndices[i]);
|
|
|
|
|
|
|
|
|
|
//int arrBlockData[NUM_CODES];
|
|
|
|
|
//arrBlockData[CODE_SIZE] = arrBlockSizes[i];
|
|
|
|
|
//arrBlockData[CODE_INDEX] = arrBlockIndices[i];
|
|
|
|
|
//// Send every process starting index of 1D represented matrix and number of
|
|
|
|
|
//// succeding indices to calculate transposition
|
|
|
|
|
//MPI_Send(arrBlockData, NUM_CODES, MPI_INT, i, 1, MPI_COMM_WORLD);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
//for (int i = 0; i < numProcesses; i++) {
|
|
|
|
|
//printf("size[%d] = %d\tindex[%d] = %d\n", i, arrBlockSizes[i], i, arrBlockIndices[i]);
|
|
|
|
|
//}
|
|
|
|
|