XBT_PUBLIC(void*) smpi_shared_set_call(const char* func, const char* input, void* data);
#define SMPI_SHARED_CALL(func, input, ...) \
(smpi_shared_known_call(#func, input) ? smpi_shared_get_call(#func, input) \
- : smpi_shared_set_call(#func, input, (void*)(func(__VA_ARGS__))))
+ : smpi_shared_set_call(#func, input, (func(__VA_ARGS__))))
/* Fortran specific stuff */
XBT_PUBLIC(int) __attribute__((weak)) smpi_simulated_main_(int argc, char** argv);
#include <stdint.h>
#include <inttypes.h>
-uint64_t hash(char *str);
+void* hash(char *str, uint64_t* ans);
-uint64_t hash(char *str)
+void* hash(char *str, uint64_t* ans)
{
- uint64_t 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;
}
//Try SMPI_SHARED_CALL function, which should call hash only once and for all.
char *str = strdup("onceandforall");
if(rank==size-1){
- *buf=(uint64_t)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;