From: Augustin Degomme Date: Tue, 25 Jun 2013 09:34:18 +0000 (+0200) Subject: Add a test for SMPI shared malloc and free X-Git-Tag: v3_9_90~229 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/3c5f5f80d481830f70dbece02adba58e296a6f00 Add a test for SMPI shared malloc and free --- diff --git a/buildtools/Cmake/AddTests.cmake b/buildtools/Cmake/AddTests.cmake index c22895f744..a17670136e 100644 --- a/buildtools/Cmake/AddTests.cmake +++ b/buildtools/Cmake/AddTests.cmake @@ -346,6 +346,7 @@ if(NOT enable_memcheck) ADD_TEST(smpi-struct-thread ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/struct.tesh) ADD_TEST(smpi-pt2pt-thread ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/pt2pt.tesh) ADD_TEST(smpi-compute-thread ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/compute.tesh) + ADD_TEST(smpi-shared-thread ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:thread --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/shared.tesh) if(CONTEXT_UCONTEXT) ADD_TEST(smpi-bcast-ucontext ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/bcast.tesh) ADD_TEST(smpi-reduce-ucontext ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/reduce.tesh) @@ -355,6 +356,7 @@ if(NOT enable_memcheck) ADD_TEST(smpi-struct-ucontext ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/struct.tesh) ADD_TEST(smpi-pt2pt-ucontext ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/pt2pt.tesh) ADD_TEST(smpi-compute-ucontext ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/compute.tesh) + ADD_TEST(smpi-shared-ucontext ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:ucontext --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/shared.tesh) endif() if(HAVE_RAWCTX) ADD_TEST(smpi-bcast-raw ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/bcast.tesh) @@ -365,6 +367,7 @@ if(NOT enable_memcheck) ADD_TEST(smpi-struct-raw ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/struct.tesh) ADD_TEST(smpi-pt2pt-raw ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/pt2pt.tesh) ADD_TEST(smpi-compute-raw ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/compute.tesh) + ADD_TEST(smpi-shared-raw ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cfg contexts/factory:raw --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/shared.tesh) endif() if(HAVE_TRACING) ADD_TEST(smpi-tracing-ptp ${CMAKE_BINARY_DIR}/bin/tesh ${TESH_OPTION} --cd ${CMAKE_BINARY_DIR}/examples/smpi ${CMAKE_HOME_DIRECTORY}/examples/smpi/tracing/smpi_traced.tesh) diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 922e0f2656..52e112d215 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -516,7 +516,7 @@ XBT_PUBLIC(void*) smpi_shared_get_call(const char* func, const char* input); 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, func(__VA_ARGS__))) + : smpi_shared_set_call(#func, input, (void*)(func(__VA_ARGS__)))) /* Fortran specific stuff */ XBT_PUBLIC(int) __attribute__((weak)) smpi_simulated_main_(int argc, char** argv); diff --git a/teshsuite/smpi/CMakeLists.txt b/teshsuite/smpi/CMakeLists.txt index 1fd4ab6c22..81c036fab5 100644 --- a/teshsuite/smpi/CMakeLists.txt +++ b/teshsuite/smpi/CMakeLists.txt @@ -25,6 +25,7 @@ if(enable_smpi) add_executable(compute compute.c) add_executable(compute2 compute2.c) add_executable(compute3 compute3.c) + add_executable(shared shared.c) add_executable(pingpong pingpong.c) add_executable(scatter scatter.c) add_executable(reduce reduce.c) @@ -51,6 +52,7 @@ if(enable_smpi) target_link_libraries(bcast_coll simgrid) target_link_libraries(barrier_coll simgrid) target_link_libraries(compute simgrid) + target_link_libraries(shared simgrid) target_link_libraries(compute2 simgrid) target_link_libraries(compute3 simgrid) target_link_libraries(pingpong simgrid) @@ -90,6 +92,7 @@ set(tesh_files ${CMAKE_CURRENT_SOURCE_DIR}/bcast.tesh ${CMAKE_CURRENT_SOURCE_DIR}/bcast_coll.tesh ${CMAKE_CURRENT_SOURCE_DIR}/compute.tesh + ${CMAKE_CURRENT_SOURCE_DIR}/shared.tesh ${CMAKE_CURRENT_SOURCE_DIR}/hvector.tesh ${CMAKE_CURRENT_SOURCE_DIR}/indexed.tesh ${CMAKE_CURRENT_SOURCE_DIR}/pt2pt.tesh @@ -124,6 +127,7 @@ set(examples_src ${CMAKE_CURRENT_SOURCE_DIR}/sendrecv.c ${CMAKE_CURRENT_SOURCE_DIR}/reduce.c ${CMAKE_CURRENT_SOURCE_DIR}/compute2.c + ${CMAKE_CURRENT_SOURCE_DIR}/shared.c ${CMAKE_CURRENT_SOURCE_DIR}/split.c ${CMAKE_CURRENT_SOURCE_DIR}/dsend.c ${CMAKE_CURRENT_SOURCE_DIR}/ttest01.c diff --git a/teshsuite/smpi/shared.c b/teshsuite/smpi/shared.c new file mode 100644 index 0000000000..0d988a9f39 --- /dev/null +++ b/teshsuite/smpi/shared.c @@ -0,0 +1,59 @@ +/* Copyright (c) 2009-2012. The SimGrid Team. All rights reserved. */ + +/* This example should be instructive to learn about SMPI_SAMPLE_LOCAL and + SMPI_SAMPLE_GLOBAL macros for execution sampling */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include +#include + +unsigned long hash(char *str); + +unsigned long hash(char *str) +{ + unsigned long hash = 5381; + int c; + printf("hashing !\n"); + while ((c = *str++)!=0) + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + return hash; +} + + +int main(int argc, char *argv[]) +{ + MPI_Init(&argc, &argv); + int rank, size; + 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)); + //one writes data in it + if(rank==0){ + *buf=size; + } + + MPI_Barrier(MPI_COMM_WORLD); + //everyobne reads from it. + printf("[%d] The value in the shared buffer is: %lu\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); + } + + MPI_Barrier(MPI_COMM_WORLD); + + printf("[%d] After change, the value in the shared buffer is: %lu\n", rank, *buf); + + + SMPI_SHARED_FREE(buf); + + MPI_Finalize(); + return 0; +} diff --git a/teshsuite/smpi/shared.tesh b/teshsuite/smpi/shared.tesh new file mode 100644 index 0000000000..31d4c71a4d --- /dev/null +++ b/teshsuite/smpi/shared.tesh @@ -0,0 +1,20 @@ +p Test compute +! setenv LD_LIBRARY_PATH=../../lib +! output sort +! timeout 5 +$ ../../bin/smpirun -platform ${srcdir:=.}/../../examples/msg/small_platform_with_routers.xml -hostfile ${srcdir:=.}/hostfile -np 4 ./shared +> [0.000000] [surf_config/INFO] Switching workstation model to compound since you changed the network and/or cpu model(s) +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'maxmin/precision' to '1e-9' +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'SMPI' +> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/TCP_gamma' to '4194304' +> [0] After change, the value in the shared buffer is: 16053117601147974045 +> [0] The value in the shared buffer is: 4 +> [1] After change, the value in the shared buffer is: 16053117601147974045 +> [1] The value in the shared buffer is: 4 +> [2] After change, the value in the shared buffer is: 16053117601147974045 +> [2] The value in the shared buffer is: 4 +> [3] After change, the value in the shared buffer is: 16053117601147974045 +> [3] The value in the shared buffer is: 4 +> hashing ! + +