73 const int nrows_max,
const int ncols_min,
79 int *row_sizes = malloc(nrows *
sizeof(
int));
80 int *col_sizes = malloc(ncols *
sizeof(
int));
81 assert(row_sizes != NULL && col_sizes != NULL);
82 assert(0 < nrows_min && nrows_min <= nrows_max);
83 assert(0 < ncols_min && ncols_min <= ncols_max);
84 if (nrows_min != nrows_max) {
85 const int row_size = nrows_max - nrows_min + 1;
86 for (
int i = 0;
i < nrows;
i++) {
87 row_sizes[
i] = rand() % row_size + 1;
90 for (
int i = 0;
i < nrows;
i++) {
91 row_sizes[
i] = nrows_max;
94 if (ncols_min != ncols_max) {
95 const int col_size = ncols_max - ncols_min + 1;
96 for (
int i = 0;
i < ncols;
i++) {
97 col_sizes[
i] = rand() % col_size + 1;
100 for (
int i = 0;
i < ncols;
i++) {
101 col_sizes[
i] = ncols_max;
105 dbm_create(&matrix, dist,
"some name", nrows, ncols, row_sizes, col_sizes);
106 dbm_distribution_release(dist);
118 const int *row_sizes, *col_sizes;
125#pragma omp for collapse(2)
126 for (
int row = 0; row < nrows; row++) {
127 for (
int col = 0; col < ncols; col++) {
128 if (dbm_get_stored_coordinates(matrix, row, col) ==
134 int *reserve_row = malloc(nblocks *
sizeof(
int));
135 int *reserve_col = malloc(nblocks *
sizeof(
int));
136 assert(reserve_row != NULL && reserve_col != NULL);
138#pragma omp for collapse(2)
139 for (
int row = 0; row < nrows; row++) {
140 for (
int col = 0; col < ncols; col++) {
141 if (dbm_get_stored_coordinates(matrix, row, col) ==
143 reserve_row[iblock] = row;
144 reserve_col[iblock] = col;
149 assert(iblock == nblocks);
150 dbm_reserve_blocks(matrix, nblocks, reserve_row, reserve_col);
187#if defined(DBM_VALIDATE_AGAINST_LIBXSMM) && defined(__LIBXSMM)
196 dbm_create(&matrix_c, dist_c,
"result", M, N, matrix_a->
row_sizes,
198 dbm_distribution_release(dist_c);
206 const double time_start_multiply = omp_get_wtime();
207 dbm_multiply(
false,
false, 1.0, matrix_a, matrix_b, 1.0, matrix_c,
false,
209 const double time_end_multiply = omp_get_wtime();
213#if defined(DBM_VALIDATE_AGAINST_LIBXSMM) && defined(__LIBXSMM)
214 const double expected = 0, checksum = 0;
216 const double expected = (uint64_t)M * m * N * n * K * K * k * k;
217 const double checksum = dbm_checksum(matrix_c);
220 dbm_release(matrix_a);
221 dbm_release(matrix_b);
222 dbm_release(matrix_c);
225 printf(
"%5i x %5i x %5i with %3i x %3i x %3i blocks: ", M, N, K, m, n, k);
227 if (checksum == expected) {
230 const double duration = time_end_multiply - time_start_multiply;
231 printf(
"%6.3f s => %6.1f GFLOP/s\n", duration, 1e-9 * flop / duration);
236 fprintf(stderr,
"Expected checksum %f but got %f.\n", expected, checksum);
245int main(
int argc,
char *argv[]) {
246 int result = EXIT_SUCCESS;
257 if (offload_get_device_count() > 0) {
258 offload_set_chosen_device(my_rank % offload_get_device_count());
262 int dims[2] = {0, 0};
264 const int periods[2] = {
true,
true};
269 printf(
"OpenMP-threads: %i GPUs: %i", omp_get_max_threads(),
270 imin(offload_get_device_count(), nranks));
271#if defined(__LIBXSMM)
272 printf(
" Libxsmm: %s", LIBXSMM_VERSION);
274 printf(
" Libxsmm: n/a");
276#if defined(__parallel)
277 printf(
" MPI-ranks: %i MPI-cart: %i x %i", nranks, dims[0], dims[1]);
309 FILE *
const file = fopen(argv[1],
"r");
311 const char delims[] =
"x,;:|/\t ";
312 int mnk[] = {0, 0, 0},
i = 1, j = 0;
314 (NULL == file || NULL != fgets(buffer,
sizeof(buffer), file))) {
315 const char *arg = strtok(NULL != file ? buffer : argv[
i], delims);
316 for (; NULL != arg && j < 3; arg = strtok(NULL, delims), ++j) {
321 }
else if (++
i < argc) {
325 const int m = mnk[0];
326 const int n = (0 < mnk[1] ? mnk[1] : m);
327 const int k = (0 < mnk[2] ? mnk[2] : m);
328 int M = (NULL == arg ? 0 : atoi(arg)), N, K;
330 arg = strtok(NULL, delims);
331 N = (NULL == arg ? 1 : atoi(arg));
332 arg = strtok(NULL, delims);
333 K = (NULL == arg ? 1 : atoi(arg));
338 mnk[0] = mnk[1] = mnk[2] = 0;
340 fprintf(stderr,
"ERROR: invalid argument(s)\n");
341 result = EXIT_FAILURE;
350 if (EXIT_SUCCESS == result) {
353 dbm_library_finalize();