-/* Copyright (c) 2019-2021. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2019-2023. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/*#*/
/*# ==================================================================================================*/
-#include "stdio.h"
-#include "mpi.h"
+#include <mpi.h>
+#include <stdio.h>
-void multiply(float* a, float* b, float* c, int istart, int iend, int size);
-void multiply_sampled(float* a, float* b, float* c, int istart, int iend, int size);
-
-
-void multiply(float* a, float* b, float* c, int istart, int iend, int size)
+static void multiply(const float* a, const float* b, float* c, int istart, int iend, int size)
{
for (int i = istart; i <= iend; ++i) {
for (int j = 0; j < size; ++j) {
- for (int k = 0; k < size; ++k) {
- c[i*size+j] += a[i*size+k] * b[k*size+j];
- }
+ float sum = 0.0;
+ for (int k = 0; k < size; ++k) {
+ sum += a[i * size + k] * b[k * size + j];
+ }
+ c[i * size + j] += sum;
}
}
}
-void multiply_sampled(float* a, float* b, float* c, int istart, int iend, int size)
+static void multiply_sampled(const float* a, const float* b, float* c, int istart, int iend, int size)
{
//for (int i = istart; i <= iend; ++i) {
SMPI_SAMPLE_GLOBAL (int i = istart, i <= iend, ++i, 10, 0.005){
for (int j = 0; j < size; ++j) {
- for (int k = 0; k < size; ++k) {
- c[i*size+j] += a[i*size+k] * b[k*size+j];
- }
+ float sum = 0.0;
+ for (int k = 0; k < size; ++k) {
+ sum += a[i * size + k] * b[k * size + j];
+ }
+ c[i * size + j] += sum;
}
}
}
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
-
+
if(argc<2){
if (rank == 0)
printf("Usage : gemm size \"native/sampling\"\n");
float *b = (float*)malloc(sizeof(float)*size*size);
float *c = (float*)malloc(sizeof(float)*size*size);
-
MPI_Barrier(MPI_COMM_WORLD);
start = MPI_Wtime();
multiply_sampled(a, b, c, (size/nproc)*nproc, size-1, size);
}
}
-
+
MPI_Barrier(MPI_COMM_WORLD);
end = MPI_Wtime();
sec_per_matrix_mul,
flops_per_matrix_mul);
}
-
return 0;
}