-
Notifications
You must be signed in to change notification settings - Fork 0
/
coo_transpose.c
124 lines (100 loc) · 4.56 KB
/
coo_transpose.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include "../util/parse_matrix_file/read_matrix_file.h"
#include "../util/format_datatypes/COO.h"
/*
* transpose COO matrix
* assuming row major order -> sort colsand reindex row and val accordingly
*/
int main(int argc, char* argv[]) {
MPI_Init(&argc, &argv);
int rank, num_procs;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
if (rank == 0)
printf("Sparce Mat. Transpose, procs: %d\n", num_procs);
char* matrices[] = {"../matrices/standardized_matrices/dimension_100_nonzeros_100.mtx",
"../matrices/standardized_matrices/dimension_100_nonzeros_1090.mtx",
"../matrices/standardized_matrices/dimension_100_nonzeros_2080.mtx",
"../matrices/standardized_matrices/dimension_100_nonzeros_3070.mtx",
"../matrices/standardized_matrices/dimension_100_nonzeros_4060.mtx",
"../matrices/standardized_matrices/dimension_100_nonzeros_5050.mtx",
"../matrices/standardized_matrices/dimension_100_nonzeros_6040.mtx",
"../matrices/standardized_matrices/dimension_100_nonzeros_7030.mtx",
"../matrices/standardized_matrices/dimension_100_nonzeros_8020.mtx",
"../matrices/standardized_matrices/dimension_100_nonzeros_9010.mtx",
"../matrices/standardized_matrices/dimension_1000_nonzeros_100900.mtx",
"../matrices/standardized_matrices/dimension_1000_nonzeros_200800.mtx",
"../matrices/standardized_matrices/dimension_1000_nonzeros_300700.mtx",
"../matrices/standardized_matrices/dimension_1000_nonzeros_400600.mtx",
"../matrices/standardized_matrices/dimension_1000_nonzeros_500499.mtx",
"../matrices/standardized_matrices/dimension_1000_nonzeros_600400.mtx",
"../matrices/standardized_matrices/dimension_1000_nonzeros_700300.mtx",
"../matrices/standardized_matrices/dimension_1000_nonzeros_800200.mtx",
"../matrices/standardized_matrices/dimension_1000_nonzeros_900100.mtx"};
int dim;
COO coo;
double* matrix;
int* local_buf;
// int* temp_row;
double start_time, end_time, total_time;
int i, j, k, m;
for (k = 18; k < 19; k++) {
dim = getStandardMatrixDimension(matrices[k]);
matrix = malloc(dim * dim * sizeof(double));
getStandardMatrix(matrices[k], dim, matrix);
convertToCOO(&coo, dim, dim, matrix);
MPI_Barrier(MPI_COMM_WORLD);
int* row = coo.rows;
int* col = coo.cols;
double* val = coo.values;
int nz = coo.nnz;
int size = nz / num_procs;
int* temp_row = row; //placeholder value for memory
local_buf = (int*)malloc(size * sizeof(int));
total_time = 0;
for (m = 0; m < 100; m++) {
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0)
start_time = MPI_Wtime();
MPI_Scatter(row, size, MPI_INT, local_buf, size, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(local_buf, size, MPI_INT, temp_row, size, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Scatter(col, size, MPI_INT, local_buf, size, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(local_buf, size, MPI_INT, row, size, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Scatter(temp_row, size, MPI_INT, local_buf, size, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Gather(local_buf, size, MPI_INT, col, size, MPI_INT, 0, MPI_COMM_WORLD);
if (rank == 0) {
end_time = MPI_Wtime();
total_time += end_time-start_time;
/*
// print transposed CSR
printf("COO t_col: ");
for (i = 0; i < nz; ++i) {
printf("%f ", col[i]);
}
printf("\n");
printf("COO t_rowPtr: ");
for (i = 0; i <= dim; ++i) {
printf("%f ", row[i]);
}
printf("\n");
printf("COO t_val: ");
for (i = 0; i < nz; ++i) {
printf("%f ", val[i]);
}
printf("\n\n");
*/
}
}
// free(temp_row);
if (rank == 0)
printf("Matrix: %d, Avg. Time: %f seconds\n", k, total_time/50);
}
//free(temp_row);
free(local_buf);
free(matrix);
freeCOO(&coo);
MPI_Finalize();
return 0;
}