Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smells of the day
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 6 Mar 2017 20:24:24 +0000 (21:24 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 6 Mar 2017 20:24:24 +0000 (21:24 +0100)
teshsuite/smpi/bug-17132/bug-17132.c
teshsuite/smpi/macro-sample/macro-sample.c
teshsuite/smpi/pt2pt-dsend/pt2pt-dsend.c
teshsuite/smpi/pt2pt-pingpong/pt2pt-pingpong.c
teshsuite/smpi/timers/timers.c
teshsuite/smpi/type-hvector/type-hvector.c
teshsuite/smpi/type-indexed/type-indexed.c
teshsuite/smpi/type-struct/type-struct.c

index 469066b..d260080 100644 (file)
@@ -14,7 +14,6 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(MM_mpi, "Messages for this SMPI test");
 
 int main(int argc, char ** argv)
 {
-  size_t err;
   size_t M = 8*1024;
   size_t N = 32*1024;
 
@@ -27,9 +26,11 @@ int main(int argc, char ** argv)
   double *b = malloc(sizeof(double) * N);
 
   // A broadcast
-  err = MPI_Bcast(a, M, MPI_DOUBLE, 0, MPI_COMM_WORLD);
+  size_t err = MPI_Bcast(a, M, MPI_DOUBLE, 0, MPI_COMM_WORLD);
   if (err != MPI_SUCCESS) {
-    perror("Error Bcast A\n"); MPI_Finalize(); exit(-1);
+    perror("Error Bcast A\n");
+    MPI_Finalize();
+    exit(-1);
   }
 
 //  Uncommenting this barrier fixes it!
@@ -38,7 +39,9 @@ int main(int argc, char ** argv)
   // Another broadcast
   err = MPI_Bcast(b, N, MPI_DOUBLE, 0, MPI_COMM_WORLD );
   if (err != MPI_SUCCESS) {
-    perror("Error Bcast B\n"); MPI_Finalize(); exit(-1);
+    perror("Error Bcast B\n");
+    MPI_Finalize();
+    exit(-1);
   }
 
   // Commenting out this barrier fixes it!!
index 9f8546d..4ae5dba 100644 (file)
@@ -13,8 +13,7 @@
 static double compute(double d0)
 {
   double d = d0;
-  int j;
-  for (j = 0; j < 100 * 1000 * 1000; j++) { /* 100 kflop */
+  for (int j = 0; j < 100 * 1000 * 1000; j++) { /* 100 kflop */
     if (d < 100000) {
       d = d * d;
     } else {
@@ -26,14 +25,12 @@ static double compute(double d0)
 
 int main(int argc, char *argv[])
 {
-  int verbose;
-  int i, n;
-  double d;
+  int n;
   MPI_Init(&argc, &argv);
-  verbose = argc <= 1;
+  int verbose = argc <= 1;
   MPI_Comm_size(MPI_COMM_WORLD, &n);
-  d = 2.0;
-  for (i = 0; i < 5; i++) {
+  double d = 2.0;
+  for (int i = 0; i < 5; i++) {
     /* I want no more than n + 1 benchs (thres < 0) */
     SMPI_SAMPLE_GLOBAL(n + 1, -1) {
       if (verbose)
@@ -47,7 +44,7 @@ int main(int argc, char *argv[])
   }
 
   n = 0;
-  for (i = 0; i < 5; i++) {
+  for (int i = 0; i < 5; i++) {
     /* I want the standard error to go below 0.1 second.
      * Two tests at least will be run (count is not > 0) */
     SMPI_SAMPLE_LOCAL(0, 0.1) {
index 1404684..57dcf03 100644 (file)
@@ -40,7 +40,6 @@ int main(int argc, char *argv[]) {
     }
   }
 
-
   XBT_INFO("rank %d: data exchanged", rank);
   MPI_Finalize();
   return 0;
index 62afcde..673bf16 100644 (file)
@@ -1,6 +1,6 @@
-/* A simple example pingpong pogram to test MPI_Send and MPI_Recv */
+/* A simple example ping-pong program to test MPI_Send and MPI_Recv */
 
-/* Copyright (c) 2009-2010, 2012-2014. The SimGrid Team.
+/* Copyright (c) 2009-2010, 2012-2014, 2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 
 int main(int argc, char *argv[])
 {
-  const int tag1 = 42, tag2 = 43;       /* Message tag */
-  int rank, size;
+  const int tag1 = 42;
+  const int tag2 = 43; /* Message tag */
+  int size;
+  int rank;
   int msg = 99;
-  int err;
-  int pivot;
   MPI_Status status;
 
-  err = MPI_Init(&argc, &argv); /* Initialize MPI */
+  int err = MPI_Init(&argc, &argv); /* Initialize MPI */
   if (err != MPI_SUCCESS) {
     printf("MPI initialization failed!\n");
     exit(1);
@@ -34,8 +34,8 @@ int main(int argc, char *argv[])
     printf("\n    *** Ping-pong test (MPI_Send/MPI_Recv) ***\n\n");
   }
 
-  /* start pingpong tests between several pairs */
-  for (pivot = 0; pivot < size - 1; pivot++) {
+  /* start ping-pong tests between several pairs */
+  for (int pivot = 0; pivot < size - 1; pivot++) {
     if (pivot == rank) {
       printf("\n== pivot=%d : pingpong [%d] <--> [%d]\n", pivot, pivot, pivot + 1);
 
index 3d7dcbb..18ff5d8 100644 (file)
@@ -8,59 +8,60 @@
 #include <time.h>
 #endif
 
+// Test if we correctly intercept gettimeofday and clock_gettime, and sleeps
 
-//Test if we correctly intercept gettimeofday and clock_gettime, and sleeps
-
-int main( int argc, char *argv[] )
+int main(int argc, char* argv[])
 {
-    MPI_Init( &argc, &argv );
+  MPI_Init(&argc, &argv);
 
-    //gettimeofday - First test that two consecutive calls will return the same
-    //time, as computing power is set to -1
+  // gettimeofday - First test that two consecutive calls will return the same
+  // time, as computing power is set to -1
 
-    struct timeval tv1, tv2;
-    gettimeofday (&tv1, NULL);
-    gettimeofday (&tv2, NULL);
-    if ((tv1.tv_sec != tv2.tv_sec) || (tv1.tv_usec != tv2.tv_usec))
-      printf("Error, two consecutive calls to gettimeofday did not return same time (with cpu_threshold set to 0)\n");
+  struct timeval tv1;
+  struct timeval tv2;
+  gettimeofday(&tv1, NULL);
+  gettimeofday(&tv2, NULL);
+  if ((tv1.tv_sec != tv2.tv_sec) || (tv1.tv_usec != tv2.tv_usec))
+    printf("Error, two consecutive calls to gettimeofday did not return same time (with cpu_threshold set to 0)\n");
 
-    //sleep one 1 second
-    gettimeofday (&tv1, NULL);
-    sleep(1);
-    gettimeofday (&tv2, NULL);
-    long res = ((tv2.tv_sec * 1000000 + tv2.tv_usec)) - ((tv1.tv_sec * 1000000 + tv1.tv_usec));
-    if (res < 999998 || res > 1000002)
-      printf("Error, sleep(1) did not exactly slept 1s\n");
+  // sleep one 1 second
+  gettimeofday(&tv1, NULL);
+  sleep(1);
+  gettimeofday(&tv2, NULL);
+  long res = ((tv2.tv_sec * 1000000 + tv2.tv_usec)) - ((tv1.tv_sec * 1000000 + tv1.tv_usec));
+  if (res < 999998 || res > 1000002)
+    printf("Error, sleep(1) did not exactly slept 1s\n");
 
-    //usleep 100 us
-    gettimeofday (&tv1, NULL);
-    usleep(100);
-    gettimeofday (&tv2, NULL);
-    res = ((tv2.tv_sec * 1000000 + tv2.tv_usec)) - ((tv1.tv_sec * 1000000 + tv1.tv_usec));
-    if (res <98 || res > 102)
-      printf("Error, usleep did not really sleep 100us, but %ld\n", res);
+  // usleep 100 us
+  gettimeofday(&tv1, NULL);
+  usleep(100);
+  gettimeofday(&tv2, NULL);
+  res = ((tv2.tv_sec * 1000000 + tv2.tv_usec)) - ((tv1.tv_sec * 1000000 + tv1.tv_usec));
+  if (res < 98 || res > 102)
+    printf("Error, usleep did not really sleep 100us, but %ld\n", res);
 
 
-    // clock_gettime, only if available
+  // clock_gettime, only if available
 #if _POSIX_TIMERS > 0
-    struct timespec tp1, tp2, tpsleep;
-    clock_gettime (CLOCK_REALTIME, &tp1);
-    clock_gettime (CLOCK_REALTIME, &tp2);
-    if ((tp1.tv_sec != tp2.tv_sec) || (tp1.tv_nsec != tp2.tv_nsec))
-      printf("Error, two consecutive calls to gettimeofday did not return same time (with running power to 0)\n");
-
-    //nanosleep for 100ns
-    clock_gettime (CLOCK_REALTIME, &tp1);
-    tpsleep.tv_sec=0;
-    tpsleep.tv_nsec=100;
-    nanosleep(&tpsleep, NULL);
-    clock_gettime (CLOCK_REALTIME, &tp2);
-    res = ((tp2.tv_sec * 1000000000 + tp2.tv_nsec)) - ((tp1.tv_sec * 1000000000 + tp1.tv_nsec));
-    if (res <98 || res > 102)
-      printf("Error, nanosleep did not really sleep 100ns, but %ld\n", res);
+  struct timespec tp1;
+  struct timespec tp2;
+  struct timespec tpsleep;
+  clock_gettime(CLOCK_REALTIME, &tp1);
+  clock_gettime(CLOCK_REALTIME, &tp2);
+  if ((tp1.tv_sec != tp2.tv_sec) || (tp1.tv_nsec != tp2.tv_nsec))
+    printf("Error, two consecutive calls to gettimeofday did not return same time (with running power to 0)\n");
 
+  // nanosleep for 100ns
+  clock_gettime(CLOCK_REALTIME, &tp1);
+  tpsleep.tv_sec  = 0;
+  tpsleep.tv_nsec = 100;
+  nanosleep(&tpsleep, NULL);
+  clock_gettime(CLOCK_REALTIME, &tp2);
+  res = ((tp2.tv_sec * 1000000000 + tp2.tv_nsec)) - ((tp1.tv_sec * 1000000000 + tp1.tv_nsec));
+  if (res < 98 || res > 102)
+    printf("Error, nanosleep did not really sleep 100ns, but %ld\n", res);
 #endif
 
-    MPI_Finalize();
-    return 0;
+  MPI_Finalize();
+  return 0;
 }
index 14f7ae3..3860fe2 100644 (file)
@@ -9,7 +9,7 @@
 #define SIZE 4
 
 int main(int argc, char **argv) {
-  int rank, i, j;
+  int rank;
   double a[SIZE][SIZE] = {{0}};
 
   MPI_Datatype columntype;
@@ -21,16 +21,16 @@ int main(int argc, char **argv) {
   MPI_Type_commit(&columntype);
 
     if (rank == 0) {
-      for(i=0; i <SIZE;i++)
-        for(j=0; j <SIZE;j++)
-          a[i][j] = i*SIZE+j;
+      for (int i = 0; i < SIZE; i++)
+        for (int j = 0; j < SIZE; j++)
+          a[i][j] = i * SIZE + j;
     }
 
     /* only one column is send this is an exemple for non-contignous data*/
     MPI_Bcast(a, 1, columntype, 0, MPI_COMM_WORLD);
 
-    for(i=0; i<SIZE; i++){
-      for (j=0; j < SIZE; j++) {
+    for (int i = 0; i < SIZE; i++) {
+      for (int j = 0; j < SIZE; j++) {
         printf("rank= %d, a[%d][%d]=%f\n", rank, i, j, a[i][j]);
       }
       printf("\n");
@@ -40,4 +40,3 @@ int main(int argc, char **argv) {
   MPI_Finalize();
   return 0;
 }
-
index aba7275..84e5882 100644 (file)
@@ -9,45 +9,46 @@
 
 int main(int argc, char *argv[])
 {
-    int rank, size, i;
-    MPI_Datatype type, type2;
-    int blocklen[3] = { 2, 3, 1 };
-    int displacement[3] = { 0, 3, 8 };
-    int buffer[27];
-    MPI_Status status;
-
-    MPI_Init(&argc, &argv);
-    MPI_Comm_size(MPI_COMM_WORLD, &size);
-    if (size < 2) {
-        printf("Please run with 2 processes.\n");
-        MPI_Finalize();
-        return 1;
-    }
-    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
-
-    MPI_Type_contiguous(3, MPI_INT, &type2);
-    MPI_Type_commit(&type2);
-    MPI_Type_indexed(3, blocklen, displacement, type2, &type);
-    MPI_Type_commit(&type);
-
-    if (rank == 0) {
-        for (i=0; i<27; i++)
-            buffer[i] = i;
-        MPI_Send(buffer, 1, type, 1, 123, MPI_COMM_WORLD);
-    }
-
-    if (rank == 1) {
-        for (i=0; i<27; i++)
-            buffer[i] = -1;
-        MPI_Recv(buffer, 1, type, 0, 123, MPI_COMM_WORLD, &status);
-        for (i=0; i<27; i++)
-            printf("buffer[%d] = %d\n", i, buffer[i]);
-        fflush(stdout);
-    }
-
-    MPI_Type_free(&type);
-    MPI_Type_free(&type2);
+  int rank;
+  int size;
+  MPI_Datatype type;
+  MPI_Datatype type2;
+  int blocklen[3]     = {2, 3, 1};
+  int displacement[3] = {0, 3, 8};
+  int buffer[27];
+  MPI_Status status;
+
+  MPI_Init(&argc, &argv);
+  MPI_Comm_size(MPI_COMM_WORLD, &size);
+  if (size < 2) {
+    printf("Please run with 2 processes.\n");
     MPI_Finalize();
-    return 0;
+    return 1;
+  }
+  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+
+  MPI_Type_contiguous(3, MPI_INT, &type2);
+  MPI_Type_commit(&type2);
+  MPI_Type_indexed(3, blocklen, displacement, type2, &type);
+  MPI_Type_commit(&type);
+
+  if (rank == 0) {
+    for (int i = 0; i < 27; i++)
+      buffer[i] = i;
+    MPI_Send(buffer, 1, type, 1, 123, MPI_COMM_WORLD);
+  }
+
+  if (rank == 1) {
+    for (int i = 0; i < 27; i++)
+      buffer[i] = -1;
+    MPI_Recv(buffer, 1, type, 0, 123, MPI_COMM_WORLD, &status);
+    for (int i = 0; i < 27; i++)
+      printf("buffer[%d] = %d\n", i, buffer[i]);
+    fflush(stdout);
+  }
+
+  MPI_Type_free(&type);
+  MPI_Type_free(&type2);
+  MPI_Finalize();
+  return 0;
 }
-
index 835b852..6e24484 100644 (file)
@@ -14,8 +14,8 @@ int main(int argc, char **argv)
     MPI_Datatype mystruct;
     int          blocklens[3];
     MPI_Aint     indices[3];
-    MPI_Datatype old_types[3], type2;
-    int i,j;
+    MPI_Datatype old_types[3];
+    MPI_Datatype type2;
 
     MPI_Init( &argc, &argv );
 
@@ -57,14 +57,14 @@ int main(int argc, char **argv)
 
     printf( "Process %d got %d (-2?) and %f (8.0?), tab (should be all 0): ", rank, value.a, value.b );
 
-    for(j=0; j<2;j++ )
-      for(i=0; i<3;i++ )
+    for (int j = 0; j < 2; j++)
+      for (int i = 0; i < 3; i++)
         printf("%d ", tab[j][i]);
     printf("\n");
 
     /* Clean up the type */
-    MPI_Type_free( &mystruct );
-    MPI_Type_free( &type2 );
-    MPI_Finalize( );
+    MPI_Type_free(&mystruct);
+    MPI_Type_free(&type2);
+    MPI_Finalize();
     return 0;
 }