|
|
|
@ -22,32 +22,7 @@ int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
|
|
if (numRank == 0) { |
|
|
|
|
|
|
|
|
|
// To avoid aggresive buffer growth at the beggining of the sequence
|
|
|
|
|
int sizeBufferTotal = INIT_BUFFER_SIZE; |
|
|
|
|
// Allocate enough memory for initial buffer
|
|
|
|
|
arrMatrixOriginal = my_malloc(sizeBufferTotal * sizeof(int)); |
|
|
|
|
// Open the file with input data
|
|
|
|
|
FILE *ptrFile = my_fopen(INPUTFILE, "r"); |
|
|
|
|
|
|
|
|
|
// Read line by line until the end of file
|
|
|
|
|
// TODO: remove the MAX_LINE_LENGTH limitation of strBuffer
|
|
|
|
|
char *ptrBuffer, strBuffer[MAX_LINE_LENGTH]; |
|
|
|
|
while (fgets(strBuffer, sizeof strBuffer, ptrFile) != 0) { |
|
|
|
|
// Store the pointer
|
|
|
|
|
ptrBuffer = strBuffer; |
|
|
|
|
numCols = 0; |
|
|
|
|
int numValue; |
|
|
|
|
// Read untill newline
|
|
|
|
|
while (*ptrBuffer != '\n') { |
|
|
|
|
// Grow buffer when needed
|
|
|
|
|
arrMatrixOriginal = buffer_grow(arrMatrixOriginal, numCount, &sizeBufferTotal); |
|
|
|
|
// Convert string to base 10
|
|
|
|
|
numValue = strtol(ptrBuffer, &ptrBuffer, 10); |
|
|
|
|
// Store the number read in memory
|
|
|
|
|
arrMatrixOriginal[numCount++] = numValue; |
|
|
|
|
numCols++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
arrMatrixOriginal = read_matrix_file(INPUTFILE, &numCols, &numCount); |
|
|
|
|
|
|
|
|
|
checkParallelWorth(numProcesses, numCount); |
|
|
|
|
|
|
|
|
@ -68,7 +43,7 @@ int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
|
|
arrBlockIndices[i] = numBlockIndex; |
|
|
|
|
numBlockIndex += arrBlockSizes[i]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int arrTransp[NUM_CODES]; |
|
|
|
|
arrTransp[CODE_SIZE] = arrBlockSizes[i];
|
|
|
|
|
arrTransp[CODE_INDEX] = arrBlockIndices[i];
|
|
|
|
@ -78,7 +53,7 @@ int main(int argc, char *argv[]) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//for (int i = 0; i < numProcesses; i++) {
|
|
|
|
|
//printf("size[%d] = %d\tindex[%d] = %d\n", i, arrBlockSizes[i], i, arrBlockIndices[i]);
|
|
|
|
|
//printf("size[%d] = %d\tindex[%d] = %d\n", i, arrBlockSizes[i], i, arrBlockIndices[i]);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -89,7 +64,7 @@ int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
|
|
int arrTransp[NUM_CODES]; |
|
|
|
|
MPI_Recv(arrTransp, NUM_CODES, MPI_INT, 0, NUM_CODES, MPI_COMM_WORLD, &status); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//We can calculate numRows * numCols = numCount
|
|
|
|
|
int numRows = numCount / numCols; |
|
|
|
|
int *arrIndicesSub = my_malloc(numCount * sizeof(int)); |
|
|
|
@ -102,22 +77,22 @@ int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
|
|
//if (numRank == 0)
|
|
|
|
|
MPI_Gatherv(arrIndicesSub, arrTransp[CODE_SIZE], MPI_INT, arrIndicesTransp, arrBlockSizes, arrBlockIndices,
|
|
|
|
|
MPI_INT, 0, MPI_COMM_WORLD); |
|
|
|
|
MPI_INT, 0, MPI_COMM_WORLD); |
|
|
|
|
|
|
|
|
|
//if (numRank == 0 ) {
|
|
|
|
|
//printf("original matrix: \n");
|
|
|
|
|
//for (int i = 0; i < numCount; i++) {
|
|
|
|
|
//printf("%d ", arrMatrixOriginal[i]);
|
|
|
|
|
//if ((i + 1) % numCols == 0)
|
|
|
|
|
//printf("\n");
|
|
|
|
|
//}
|
|
|
|
|
//printf("\n");
|
|
|
|
|
//printf("original matrix: \n");
|
|
|
|
|
//for (int i = 0; i < numCount; i++) {
|
|
|
|
|
//printf("%d ", arrMatrixOriginal[i]);
|
|
|
|
|
//if ((i + 1) % numCols == 0)
|
|
|
|
|
//printf("\n");
|
|
|
|
|
//}
|
|
|
|
|
//printf("\n");
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if (numRank == 0) { |
|
|
|
|
printf("transposed matrix:"); |
|
|
|
|
for (int i = 0; i < numCount; i++) { |
|
|
|
|
if (i % numRows == 0) |
|
|
|
|
if (i % numRows == 0) |
|
|
|
|
printf("\n"); |
|
|
|
|
printf("%d ", arrMatrixOriginal[arrIndicesTransp[i]]); |
|
|
|
|
} |
|
|
|
|