Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add missing copyright notes
[simgrid.git] / examples / smpi / gemm / gemm.c
index 196b2fd90fe8306bdf387e1eda03ea27a7ba8958..b9f0635d704db7b12734858a292923a347508034 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019-2022. 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;
         }
     }
 }