Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix errors in make distcheck.
[simgrid.git] / teshsuite / smpi / shared.c
index 0d988a9..1a6ac05 100644 (file)
@@ -8,17 +8,19 @@
 
 #include <stdio.h>
 #include <mpi.h>
+#include <stdint.h>
+#include <inttypes.h>
 
-unsigned long hash(char *str);
+void* hash(char *str, uint64_t* ans);
 
-unsigned long hash(char *str)
+void* hash(char *str, uint64_t* ans)
 {
-  unsigned long hash = 5381;
+  *ans=5381;
   int c;
   printf("hashing !\n");
   while ((c = *str++)!=0)
-    hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
-  return hash;
+    *ans = ((*ans << 5) + *ans) + c; /* hash * 33 + c */
+  return NULL;
 }
 
 
@@ -29,7 +31,7 @@ int main(int argc, char *argv[])
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   MPI_Comm_size(MPI_COMM_WORLD, &size);
   //Let's Allocate a shared memory buffer
-  unsigned long* buf = SMPI_SHARED_MALLOC(sizeof(unsigned long));
+  uint64_t* buf = SMPI_SHARED_MALLOC(sizeof(uint64_t));
   //one writes data in it
   if(rank==0){
     *buf=size;  
@@ -37,22 +39,23 @@ int main(int argc, char *argv[])
   
   MPI_Barrier(MPI_COMM_WORLD);
   //everyobne reads from it. 
-  printf("[%d] The value in the shared buffer is: %lu\n", rank, *buf);
+  printf("[%d] The value in the shared buffer is: %" PRIu64"\n", rank, *buf);
   
   
   MPI_Barrier(MPI_COMM_WORLD);
   //Try SMPI_SHARED_CALL function, which should call hash only once and for all.
   char *str = strdup("onceandforall");
   if(rank==size-1){
-    *buf=(unsigned long)SMPI_SHARED_CALL(hash,str,str);  
+    SMPI_SHARED_CALL(hash,str,str,buf);  
   }
   
   MPI_Barrier(MPI_COMM_WORLD);
   
-  printf("[%d] After change, the value in the shared buffer is: %lu\n", rank, *buf);
-  
+  printf("[%d] After change, the value in the shared buffer is: %" PRIu64"\n", rank, *buf);
   
   SMPI_SHARED_FREE(buf);  
+  buf=NULL;  
+  free(str);
     
   MPI_Finalize();
   return 0;