Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove useless allocations.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Oct 2017 07:41:57 +0000 (08:41 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Oct 2017 14:44:29 +0000 (15:44 +0100)
teshsuite/smpi/coll-alltoallv/coll-alltoallv.c
teshsuite/smpi/macro-shared/macro-shared.c
teshsuite/xbt/parallel_log_crashtest/parallel_log_crashtest.c

index 107179f..233b978 100644 (file)
@@ -44,7 +44,7 @@
    <2> rbuf: (#9):   [3][4][103][104][203][204][-1][-1][-1]
 */
 
    <2> rbuf: (#9):   [3][4][103][104][203][204][-1][-1][-1]
 */
 
-static void print_buffer_int(void *buf, int len, char *msg, int rank)
+static void print_buffer_int(void *buf, int len, const char *msg, int rank)
 {
   printf("[%d] %s (#%d): ", rank, msg, len);
   for (int tmp = 0; tmp < len; tmp++) {
 {
   printf("[%d] %s (#%d): ", rank, msg, len);
   for (int tmp = 0; tmp < len; tmp++) {
@@ -52,7 +52,6 @@ static void print_buffer_int(void *buf, int len, char *msg, int rank)
     printf("[%d]", v[tmp]);
   }
   printf("\n");
     printf("[%d]", v[tmp]);
   }
   printf("\n");
-  free(msg);
 }
 
 int main(int argc, char **argv)
 }
 
 int main(int argc, char **argv)
@@ -94,15 +93,15 @@ int main(int argc, char **argv)
     sdispls[i] = (i * (i + 1)) / 2;
   }
 
     sdispls[i] = (i * (i + 1)) / 2;
   }
 
-  print_buffer_int( sbuf, size*size, strdup("sbuf:"),rank);
-  print_buffer_int( sendcounts, size, strdup("scount:"),rank);
-  print_buffer_int( recvcounts, size, strdup("rcount:"),rank);
-  print_buffer_int( sdispls, size, strdup("sdisp:"),rank);
-  print_buffer_int( rdispls, size, strdup("rdisp:"),rank);
+  print_buffer_int(sbuf, size * size, "sbuf:", rank);
+  print_buffer_int(sendcounts, size, "scount:", rank);
+  print_buffer_int(recvcounts, size, "rcount:", rank);
+  print_buffer_int(sdispls, size, "sdisp:", rank);
+  print_buffer_int(rdispls, size, "rdisp:", rank);
 
   MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT, rbuf, recvcounts, rdispls, MPI_INT, comm);
 
 
   MPI_Alltoallv(sbuf, sendcounts, sdispls, MPI_INT, rbuf, recvcounts, rdispls, MPI_INT, comm);
 
-  print_buffer_int( rbuf, size*size, strdup("rbuf:"),rank);
+  print_buffer_int(rbuf, size * size, "rbuf:", rank);
 
   MPI_Barrier(MPI_COMM_WORLD);
   if (0 == rank) {
 
   MPI_Barrier(MPI_COMM_WORLD);
   if (0 == rank) {
index 1e09ac4..51da71b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009-2015. The SimGrid Team.
+/* Copyright (c) 2009-2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -11,9 +11,9 @@
 #include <stdint.h>
 #include <inttypes.h>
 
 #include <stdint.h>
 #include <inttypes.h>
 
-static void* hash(char *str, uint64_t* ans)
+static void* hash(const char *str, uint64_t* ans)
 {
 {
-  char *tohash = str;
+  const char *tohash = str;
   *ans=5381;
   printf("hashing !\n");
   int c = *tohash;
   *ans=5381;
   printf("hashing !\n");
   int c = *tohash;
@@ -45,7 +45,7 @@ int main(int argc, char *argv[])
 
   MPI_Barrier(MPI_COMM_WORLD);
   //Try SMPI_SHARED_CALL function, which should call hash only once and for all.
 
   MPI_Barrier(MPI_COMM_WORLD);
   //Try SMPI_SHARED_CALL function, which should call hash only once and for all.
-  char *str = strdup("onceandforall");
+  static const char str[] = "onceandforall";
   if(rank==size-1){
     SMPI_SHARED_CALL(hash,str,str,buf);
   }
   if(rank==size-1){
     SMPI_SHARED_CALL(hash,str,str,buf);
   }
@@ -55,7 +55,6 @@ int main(int argc, char *argv[])
   printf("[%d] After change, the value in the shared buffer is: %" PRIu64"\n", rank, *buf);
 
   SMPI_SHARED_FREE(buf);
   printf("[%d] After change, the value in the shared buffer is: %" PRIu64"\n", rank, *buf);
 
   SMPI_SHARED_FREE(buf);
-  free(str);
 
   MPI_Finalize();
   return 0;
 
   MPI_Finalize();
   return 0;
index d904a1a..b519739 100644 (file)
@@ -1,6 +1,6 @@
 /* synchro_crashtest -- tries to crash the logging mechanism by doing parallel logs*/
 
 /* synchro_crashtest -- tries to crash the logging mechanism by doing parallel logs*/
 
-/* Copyright (c) 2007-2014. The SimGrid Team.
+/* Copyright (c) 2007-2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -43,9 +43,9 @@ static int crasher()
 
   /* spawn threads */
   for (int i = 0; i < crasher_amount; i++) {
 
   /* spawn threads */
   for (int i = 0; i < crasher_amount; i++) {
-    char *name = bprintf("thread %d", i);
+    char name[16];
+    snprintf(name, sizeof name, "thread %d", i);
     crashers[i] = xbt_os_thread_create(name, &crasher_thread, &id[i], NULL );
     crashers[i] = xbt_os_thread_create(name, &crasher_thread, &id[i], NULL );
-    free(name);
   }
 
   /* wait for them */
   }
 
   /* wait for them */