Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to make the shared test compatible with 32bit architectures
[simgrid.git] / teshsuite / smpi / shared.c
1 /* Copyright (c) 2009-2012. The SimGrid Team. All rights reserved.          */
2
3 /* This example should be instructive to learn about SMPI_SAMPLE_LOCAL and 
4    SMPI_SAMPLE_GLOBAL macros for execution sampling */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include <stdio.h>
10 #include <mpi.h>
11 #include <stdint.h>
12
13 unsigned long hash(char *str);
14
15 uint64_t hash(char *str)
16 {
17   uint64_t hash = 5381;
18   int c;
19   printf("hashing !\n");
20   while ((c = *str++)!=0)
21     hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
22   return hash;
23 }
24
25
26 int main(int argc, char *argv[])
27 {
28   MPI_Init(&argc, &argv);
29   int rank, size;
30   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
31   MPI_Comm_size(MPI_COMM_WORLD, &size);
32   //Let's Allocate a shared memory buffer
33   uint64_t* buf = SMPI_SHARED_MALLOC(sizeof(uint64_t));
34   //one writes data in it
35   if(rank==0){
36     *buf=size;  
37   }
38   
39   MPI_Barrier(MPI_COMM_WORLD);
40   //everyobne reads from it. 
41   printf("[%d] The value in the shared buffer is: %zu\n", rank, *buf);
42   
43   
44   MPI_Barrier(MPI_COMM_WORLD);
45   //Try SMPI_SHARED_CALL function, which should call hash only once and for all.
46   char *str = strdup("onceandforall");
47   if(rank==size-1){
48     *buf=(uint64_t)SMPI_SHARED_CALL(hash,str,str);  
49   }
50   
51   MPI_Barrier(MPI_COMM_WORLD);
52   
53   printf("[%d] After change, the value in the shared buffer is: %lu\n", rank, *buf);
54   
55   
56   SMPI_SHARED_FREE(buf);  
57     
58   MPI_Finalize();
59   return 0;
60 }