From fcd4e90d40b0162b583075c5645aacf40392dfc9 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Mon, 6 Mar 2017 21:24:24 +0100 Subject: [PATCH] smells of the day --- teshsuite/smpi/bug-17132/bug-17132.c | 11 ++- teshsuite/smpi/macro-sample/macro-sample.c | 15 ++-- teshsuite/smpi/pt2pt-dsend/pt2pt-dsend.c | 1 - .../smpi/pt2pt-pingpong/pt2pt-pingpong.c | 18 ++-- teshsuite/smpi/timers/timers.c | 87 ++++++++++--------- teshsuite/smpi/type-hvector/type-hvector.c | 13 ++- teshsuite/smpi/type-indexed/type-indexed.c | 81 ++++++++--------- teshsuite/smpi/type-struct/type-struct.c | 14 +-- 8 files changed, 120 insertions(+), 120 deletions(-) diff --git a/teshsuite/smpi/bug-17132/bug-17132.c b/teshsuite/smpi/bug-17132/bug-17132.c index 469066b747..d260080644 100644 --- a/teshsuite/smpi/bug-17132/bug-17132.c +++ b/teshsuite/smpi/bug-17132/bug-17132.c @@ -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!! diff --git a/teshsuite/smpi/macro-sample/macro-sample.c b/teshsuite/smpi/macro-sample/macro-sample.c index 9f8546de1a..4ae5dbad95 100644 --- a/teshsuite/smpi/macro-sample/macro-sample.c +++ b/teshsuite/smpi/macro-sample/macro-sample.c @@ -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) { diff --git a/teshsuite/smpi/pt2pt-dsend/pt2pt-dsend.c b/teshsuite/smpi/pt2pt-dsend/pt2pt-dsend.c index 1404684301..57dcf03eb2 100644 --- a/teshsuite/smpi/pt2pt-dsend/pt2pt-dsend.c +++ b/teshsuite/smpi/pt2pt-dsend/pt2pt-dsend.c @@ -40,7 +40,6 @@ int main(int argc, char *argv[]) { } } - XBT_INFO("rank %d: data exchanged", rank); MPI_Finalize(); return 0; diff --git a/teshsuite/smpi/pt2pt-pingpong/pt2pt-pingpong.c b/teshsuite/smpi/pt2pt-pingpong/pt2pt-pingpong.c index 62afcde78a..673bf16439 100644 --- a/teshsuite/smpi/pt2pt-pingpong/pt2pt-pingpong.c +++ b/teshsuite/smpi/pt2pt-pingpong/pt2pt-pingpong.c @@ -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 @@ -11,14 +11,14 @@ 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); diff --git a/teshsuite/smpi/timers/timers.c b/teshsuite/smpi/timers/timers.c index 3d7dcbb520..18ff5d89c5 100644 --- a/teshsuite/smpi/timers/timers.c +++ b/teshsuite/smpi/timers/timers.c @@ -8,59 +8,60 @@ #include #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; } diff --git a/teshsuite/smpi/type-hvector/type-hvector.c b/teshsuite/smpi/type-hvector/type-hvector.c index 14f7ae39cc..3860fe2c14 100644 --- a/teshsuite/smpi/type-hvector/type-hvector.c +++ b/teshsuite/smpi/type-hvector/type-hvector.c @@ -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