X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/dccf1b41e9c7b5a696f01abceaa2779fe65f154f..HEAD:/teshsuite/smpi/macro-shared/macro-shared.c diff --git a/teshsuite/smpi/macro-shared/macro-shared.c b/teshsuite/smpi/macro-shared/macro-shared.c index f3ac8488b5..fb90cb6c80 100644 --- a/teshsuite/smpi/macro-shared/macro-shared.c +++ b/teshsuite/smpi/macro-shared/macro-shared.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009-2015. The SimGrid Team. +/* Copyright (c) 2009-2023. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -11,20 +11,25 @@ #include #include -static void* hash(char *str, uint64_t* ans) +static void* hash(const char *str, uint64_t* ans) { + const char *tohash = str; *ans=5381; - int c; printf("hashing !\n"); - while ((c = *str++)!=0) + int c = *tohash; + while (c != 0) { *ans = ((*ans << 5) + *ans) + c; /* hash * 33 + c */ + tohash++; + c = *tohash; + } return NULL; } int main(int argc, char *argv[]) { MPI_Init(&argc, &argv); - int rank, size; + int rank; + int size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); //Let's Allocate a shared memory buffer @@ -40,18 +45,27 @@ 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. - char *str = strdup("onceandforall"); + static const char str[] = "onceandforall"; if(rank==size-1){ - SMPI_SHARED_CALL(hash,str,str,buf); + SMPI_SHARED_CALL(hash,str,str,buf); } MPI_Barrier(MPI_COMM_WORLD); printf("[%d] After change, the value in the shared buffer is: %" PRIu64"\n", rank, *buf); + //try to send/receive shared data, to check if we skip the copies correctly. + if(rank==0) + MPI_Send(buf, 1, MPI_AINT, 1, 100, MPI_COMM_WORLD); + else if (rank ==1) + MPI_Recv(buf, 1, MPI_AINT, 0, 100, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + + //same thing with an MPI_IN_PLACE collective (no) + if (rank == 0) + MPI_Scatter(buf, 1, MPI_AINT, MPI_IN_PLACE, -1, MPI_DATATYPE_NULL, 0, MPI_COMM_WORLD); + else + MPI_Scatter(NULL, -1, MPI_DATATYPE_NULL, buf, 1, MPI_AINT, 0, MPI_COMM_WORLD); SMPI_SHARED_FREE(buf); - buf=NULL; - free(str); MPI_Finalize(); return 0;