X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5afd75483d80ccf2c678e50f82613b3556c7ca97..3c7c64745aa5e60415bb85af482c7b0d0fca2b2b:/examples/smpi/gemm/gemm.c diff --git a/examples/smpi/gemm/gemm.c b/examples/smpi/gemm/gemm.c index 3e1580ca72..b9f0635d70 100644 --- a/examples/smpi/gemm/gemm.c +++ b/examples/smpi/gemm/gemm.c @@ -1,4 +1,4 @@ -/* 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. */ @@ -12,32 +12,32 @@ /*#*/ /*# ==================================================================================================*/ -#include "stdio.h" -#include "mpi.h" +#include +#include -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; } } } @@ -51,7 +51,7 @@ int main(int argc, char* argv[]) 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"); @@ -73,7 +73,6 @@ int main(int argc, char* argv[]) float *b = (float*)malloc(sizeof(float)*size*size); float *c = (float*)malloc(sizeof(float)*size*size); - MPI_Barrier(MPI_COMM_WORLD); start = MPI_Wtime(); @@ -130,7 +129,7 @@ int main(int argc, char* argv[]) multiply_sampled(a, b, c, (size/nproc)*nproc, size-1, size); } } - + MPI_Barrier(MPI_COMM_WORLD); end = MPI_Wtime(); @@ -151,7 +150,6 @@ int main(int argc, char* argv[]) sec_per_matrix_mul, flops_per_matrix_mul); } - return 0; }