diff --git a/CMakeLists.txt b/CMakeLists.txt index 739990e5f..f3a9c5a0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,193 +1,193 @@ #=============================================================================== # @file CMakeLists.txt # @author Nicolas Richart # @date Fri Jun 11 09:46:59 2010 # # @section LICENSE # # # # @section DESCRIPTION # #=============================================================================== #=============================================================================== # _ ,-, _ # ,--, /: :\/': :`\/: :\ # |`; ' `,' `.; `: | _ _ # | | | ' | |. | | | | # | : | F E | A S | T++ || __ _| | ____ _ _ __ | |_ _ _ # | :. | : | : | : | \ / _` | |/ / _` | '_ \| __| | | | # \__/: :.. : :.. | :.. | ) | (_| | < (_| | | | | |_| |_| | # `---',\___/,\___/ /' \__,_|_|\_\__,_|_| |_|\__|\__,_| # `==._ .. . /' # `-::-' #=============================================================================== #=============================================================================== # CMake Project #=============================================================================== cmake_minimum_required(VERSION 2.6) project(AKANTU) enable_language(CXX) #=============================================================================== # Misc. #=============================================================================== set(AKANTU_CMAKE_DIR "${AKANTU_SOURCE_DIR}/cmake") set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries.") #=============================================================================== # Version Number #=============================================================================== # AKANTU version number. An even minor number corresponds to releases. set(AKANTU_MAJOR_VERSION 0) set(AKANTU_MINOR_VERSION 1) set(AKANTU_BUILD_VERSION 0) set(AKANTU_VERSION "${AKANTU_MAJOR_VERSION}.${AKANTU_MINOR_VERSION}.${AKANTU_BUILD_VERSION}" ) # Append the library version information to the library target properties if(NOT AKANTU_NO_LIBRARY_VERSION) set(AKANTU_LIBRARY_PROPERTIES ${AKANTU_LIBRARY_PROPERTIES} VERSION "${AKANTU_VERSION}" SOVERSION "${AKANTU_MAJOR_VERSION}.${AKANTU_MINOR_VERSION}" ) endif(NOT AKANTU_NO_LIBRARY_VERSION) #=============================================================================== # Options #=============================================================================== # Debug option(AKANTU_DEBUG "Compiles akantu with the debug messages" ON) if(NOT AKANTU_DEBUG) add_definitions(-DAKANTU_NDEBUG) endif(NOT AKANTU_DEBUG) # IOHelper option(AKANTU_USE_IOHELPER "Add IOHelper support in akantu" OFF) if(AKANTU_USE_IOHELPER) include(${AKANTU_CMAKE_DIR}/FindIOHelper.cmake) if(IOHELPER_FOUND) add_definitions(-DAKANTU_USE_IOHELPER) set(AKANTU_EXTERNAL_LIB_INCLUDE_PATH ${AKANTU_EXTERNAL_LIB_INCLUDE_PATH} ${IOHELPER_INCLUDE_PATH} ) set(AKANTU_EXTERNAL_LIBRARIES ${AKANTU_EXTERNAL_LIBRARIES} ${IOHELPER_LIBRARIES} ) endif(IOHELPER_FOUND) endif(AKANTU_USE_IOHELPER) # MPI option(AKANTU_USE_MPI "Add MPI support in akantu" OFF) if(AKANTU_USE_MPI) find_package(MPI) if(MPI_FOUND) add_definitions(-DAKANTU_USE_MPI) set(AKANTU_EXTERNAL_LIB_INCLUDE_PATH ${AKANTU_EXTERNAL_LIB_INCLUDE_PATH} ${MPI_INCLUDE_PATH} ) set(AKANTU_EXTERNAL_LIBRARIES ${AKANTU_EXTERNAL_LIBRARIES} ${MPI_LIBRARY} ${MPI_EXTRA_LIBRARY} ) endif(MPI_FOUND) endif(AKANTU_USE_MPI) # Scotch option(AKANTU_USE_SCOTCH "Add Scotch support in akantu" OFF) if(AKANTU_USE_SCOTCH) include(${AKANTU_CMAKE_DIR}/FindScotch.cmake) if(SCOTCH_FOUND) add_definitions(-DAKANTU_USE_SCOTCH) set(AKANTU_EXTERNAL_LIB_INCLUDE_PATH ${AKANTU_EXTERNAL_LIB_INCLUDE_PATH} ${SCOTCH_INCLUDE_PATH} ) set(AKANTU_EXTERNAL_LIBRARIES ${AKANTU_EXTERNAL_LIBRARIES} ${SCOTCH_LIBRARIES} ) endif(SCOTCH_FOUND) endif(AKANTU_USE_SCOTCH) #=============================================================================== # Library #=============================================================================== set(AKANTU_COMMON_SRC common/aka_common.cc common/aka_extern.cc common/aka_static_memory.cc common/aka_memory.cc common/aka_vector.cc common/aka_math.cc + common/aka_error.cc fem/mesh.cc fem/fem.cc fem/element_class.cc model/solid_mechanics_model.cc model/material.cc model/materials/material_elastic.cc model/integration_scheme/central_difference.cc mesh_utils/mesh_io.cc mesh_utils/mesh_io/mesh_io_msh.cc mesh_utils/mesh_partition.cc mesh_utils/mesh_utils.cc synchronizer/ghost_synchronizer.cc synchronizer/synchronizer.cc synchronizer/communicator.cc synchronizer/static_communicator.cc ) #if(AKANTU_USE_MPI AND MPI_FOUND) # set(AKANTU_COMMON_SRC # ${AKANTU_COMMON_SRC} # synchronizer/static_communicator_mpi.cc # ) #endif(AKANTU_USE_MPI AND MPI_FOUND) if(AKANTU_USE_SCOTCH AND SCOTCH_FOUND) set(AKANTU_COMMON_SRC ${AKANTU_COMMON_SRC} mesh_utils/mesh_partition/mesh_partition_scotch.cc ) endif(AKANTU_USE_SCOTCH AND SCOTCH_FOUND) set(AKANTU_INCLUDE_DIRS common fem/ mesh_utils/ mesh_utils/mesh_io/ mesh_utils/mesh_partition/ model/ synchronizer/ ) include_directories( ${AKANTU_INCLUDE_DIRS} ${AKANTU_EXTERNAL_LIB_INCLUDE_PATH} ) add_library(akantu ${AKANTU_COMMON_SRC}) set_target_properties(akantu PROPERTIES ${AKANTU_LIBRARY_PROPERTIES}) - #=============================================================================== # Tests #=============================================================================== -option(TEST_FLAG "Activate tests" OFF) -if(TEST_FLAG) -subdirs(test) -endif(TEST_FLAG) +option(AKANTU_TESTS "Activate tests" OFF) +if(AKANTU_TESTS) + subdirs(test) +endif(AKANTU_TESTS) diff --git a/cmake/FindIOHelper.cmake b/cmake/FindIOHelper.cmake index ce3b302c1..51a6a5141 100644 --- a/cmake/FindIOHelper.cmake +++ b/cmake/FindIOHelper.cmake @@ -1,44 +1,44 @@ #=============================================================================== # @file FindIOHelper.cmake # @author Nicolas Richart # @date Tue Aug 3 16:29:57 2010 # # @brief The find_package file for IOHelper # # @section LICENSE # # # #=============================================================================== #=============================================================================== set(IOHELPER_LIBRARY "NOTFOUND" CACHE INTERNAL "Cleared" FORCE) find_library(IOHELPER_LIBRARY IOHelper PATHS ${IOHELPER_DIR} - PATH_SUFFIXES . src + PATH_SUFFIXES src ) find_path(IOHELPER_INCLUDE_PATH io_helper.h PATHS ${IOHELPER_DIR} - PATH_SUFFIXES . src + PATH_SUFFIXES src ) #=============================================================================== mark_as_advanced(IOHELPER_LIBRARY) mark_as_advanced(IOHELPER_INCLUDE_PATH) #=============================================================================== find_package(ZLIB REQUIRED) set(IOHELPER_LIBRARIES_ALL ${IOHELPER_LIBRARY} ${ZLIB_LIBRARIES}) set(IOHELPER_LIBRARIES ${IOHELPER_LIBRARIES_ALL} CACHE INTERNAL "Libraries for IOHelper" FORCE) #=============================================================================== include(FindPackageHandleStandardArgs) find_package_handle_standard_args(IOHELPER DEFAULT_MSG IOHELPER_LIBRARY IOHELPER_INCLUDE_PATH) #=============================================================================== if(NOT IOHELPER_FOUND) set(IOHELPER_DIR "" CACHE PATH "Location of IOHelper source directory.") endif(NOT IOHELPER_FOUND) diff --git a/common/aka_common.cc b/common/aka_common.cc index 49b84b139..c05efb523 100644 --- a/common/aka_common.cc +++ b/common/aka_common.cc @@ -1,43 +1,48 @@ /** * @file aka_common.cc * @author Nicolas Richart * @date Fri Jun 11 16:56:43 2010 * * @brief Initialization of global variables * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "aka_static_memory.hh" #include "static_communicator.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ void initialize(int * argc, char *** argv) { AKANTU_DEBUG_IN(); StaticMemory::getStaticMemory(); - StaticCommunicator::getStaticCommunicator(argc, argv); + StaticCommunicator * comm = StaticCommunicator::getStaticCommunicator(argc, argv); + debug::setParallelContext(comm->whoAmI(), comm->getNbProc()); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ void finalize() { AKANTU_DEBUG_IN(); if(StaticMemory::isInstantiated()) delete StaticMemory::getStaticMemory(); - if(StaticCommunicator::isInstantiated()) delete StaticCommunicator::getStaticCommunicator(); + if(StaticCommunicator::isInstantiated()) { + StaticCommunicator *comm = StaticCommunicator::getStaticCommunicator(); + comm->barrier(); + delete comm; + } AKANTU_DEBUG_OUT(); } __END_AKANTU__ diff --git a/common/aka_error.hh b/common/aka_error.hh index ca2b7e9b9..150c6698e 100644 --- a/common/aka_error.hh +++ b/common/aka_error.hh @@ -1,202 +1,214 @@ /** * @file aka_error.hh * @author Nicolas Richart * @date Mon Jun 14 11:43:22 2010 * * @brief error management and internal exceptions * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_ERROR_HH__ #define __AKANTU_ERROR_HH__ /* -------------------------------------------------------------------------- */ #include #include #ifdef AKANTU_USE_MPI #include #endif /* -------------------------------------------------------------------------- */ #include "aka_common.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ enum DebugLevel { dbl0 = 0, dblError = 0, dblAssert = 0, dbl1 = 1, dblException = 1, dblCritical = 1, dbl2 = 2, dblMajor = 2, dbl3 = 3, dblCall = 3, dblSecondary = 3, dblHead = 3, dbl4 = 4, dblWarning = 4, dbl5 = 5, dblInfo = 5, dbl6 = 6, dblIn = 6, dblOut = 6, dbl7 = 7, dbl8 = 8, dblTrace = 8, dbl9 = 9, dblAccessory = 9, dbl10 = 10, dblDump = 100 }; /* -------------------------------------------------------------------------- */ +namespace debug { + extern std::ostream & _akantu_cout; -extern std::ostream & _akantu_cout; + extern std::ostream & _akantu_debug_cout; -extern std::ostream & _akantu_debug_cout; + extern DebugLevel _debug_level; -extern DebugLevel _debug_level; + extern std::string _parallel_context; + + void setDebugLevel(const DebugLevel & level); + + void setParallelContext(int rank, int size); +}; /* -------------------------------------------------------------------------- */ /// exception class that can be thrown by akantu class Exception : public std::exception { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: //! full constructor Exception(std::string info, std::string file, unsigned int line) : _info(info), _file(file), _line(line) { } //! destructor virtual ~Exception() throw() {}; /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: virtual const char* what() const throw() { std::stringstream stream; stream << "akantu::Exception" << " : " << _info << " [" << _file << ":" << _line << "]"; return stream.str().c_str(); } virtual const char* info() const throw() { return _info.c_str(); } /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: /// exception description and additionals std::string _info; /// file it is thrown from std::string _file; /// ligne it is thrown from unsigned int _line; }; -/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ #define AKANTU_LOCATION "(" <<__FILE__ << ":" << __func__ << "():" << __LINE__ << ")" #ifndef AKANTU_USE_MPI #define AKANTU_EXIT(status) \ do { \ int * p = NULL; \ *p = 2; \ exit(status); \ } while(0) #else #define AKANTU_EXIT(status) \ do { \ int * p = NULL; \ *p = 2; \ MPI_Abort(MPI_COMM_WORLD, MPI_ERR_UNKNOWN); \ } while(0) #endif /* -------------------------------------------------------------------------- */ #define AKANTU_EXCEPTION(info) \ do { \ AKANTU_DEBUG(akantu::dblError, "!!! " << info); \ std::stringstream s_info; \ s_info << info ; \ Exception ex(s_info.str(), __FILE__, __LINE__ ); \ throw ex; \ } while(0) /* -------------------------------------------------------------------------- */ #ifdef AKANTU_NDEBUG #define AKANTU_DEBUG_TEST(level) (0) #define AKANTU_DEBUG(level,info) #define AKANTU_DEBUG_IN() #define AKANTU_DEBUG_OUT() #define AKANTU_DEBUG_INFO(info) #define AKANTU_DEBUG_WARNING(info) #define AKANTU_DEBUG_TRACE(info) #define AKANTU_DEBUG_ASSERT(test,info) #define AKANTU_DEBUG_ERROR(info) AKANTU_EXCEPTION(info) /* -------------------------------------------------------------------------- */ #else #define AKANTU_DEBUG(level,info) \ - ((akantu::_debug_level >= level) && \ - (_akantu_debug_cout << info << " " << AKANTU_LOCATION << std::endl)) + ((::akantu::debug::_debug_level >= level) && \ + (::akantu::debug::_akantu_debug_cout \ + << ::akantu::debug::_parallel_context \ + << info << " " \ + << AKANTU_LOCATION \ + << std::endl)) #define AKANTU_DEBUG_TEST(level) \ - (akantu::_debug_level >= (level)) + (::akantu::debug::_debug_level >= (level)) -#define AKANTU_DEBUG_IN() \ - AKANTU_DEBUG(akantu::dblIn , "==> " << __func__ << "()") +#define AKANTU_DEBUG_IN() \ + AKANTU_DEBUG(::akantu::dblIn , "==> " << __func__ << "()") -#define AKANTU_DEBUG_OUT() \ - AKANTU_DEBUG(akantu::dblOut , "<== " << __func__ << "()") +#define AKANTU_DEBUG_OUT() \ + AKANTU_DEBUG(::akantu::dblOut , "<== " << __func__ << "()") #define AKANTU_DEBUG_INFO(info) \ - AKANTU_DEBUG(akantu::dblInfo , "--- " << info) + AKANTU_DEBUG(::akantu::dblInfo , "--- " << info) #define AKANTU_DEBUG_WARNING(info) \ - AKANTU_DEBUG(akantu::dblWarning, "??? " << info) + AKANTU_DEBUG(::akantu::dblWarning, "??? " << info) #define AKANTU_DEBUG_TRACE(info) \ - AKANTU_DEBUG(akantu::dblTrace , ">>> " << info) + AKANTU_DEBUG(::akantu::dblTrace , ">>> " << info) #define AKANTU_DEBUG_ASSERT(test,info) \ do { \ if (!(test)) { \ - AKANTU_DEBUG(dblAssert, "assert [" << #test << "] " \ + AKANTU_DEBUG(::akantu::dblAssert, "assert [" << #test << "] " \ << "!!! " << info); \ AKANTU_EXIT(EXIT_FAILURE); \ } \ } while(0) #define AKANTU_DEBUG_ERROR(info) \ do { \ - AKANTU_DEBUG(akantu::dblError, "!!! " << info); \ + AKANTU_DEBUG(::akantu::dblError, "!!! " << info); \ AKANTU_EXIT(EXIT_FAILURE); \ } while(0) -#endif +#endif // AKANTU_NDEBUG /* -------------------------------------------------------------------------- */ __END_AKANTU__ #endif /* __AKANTU_ERROR_HH__ */ // LocalWords: acessory diff --git a/common/aka_extern.cc b/common/aka_extern.cc index 28241760f..f9300d8e5 100644 --- a/common/aka_extern.cc +++ b/common/aka_extern.cc @@ -1,43 +1,48 @@ /** * @file aka_extern.cpp * @author Nicolas Richart * @date Mon Jun 14 14:34:14 2010 * * @brief initialisation of all global variables * to insure the order of creation * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #include /* -------------------------------------------------------------------------- */ #include "aka_common.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /** \todo write function to get this * values from the environment or a config file */ /* -------------------------------------------------------------------------- */ /* error.hpp variables */ /* -------------------------------------------------------------------------- */ -/// standard output for debug messages -std::ostream & _akantu_debug_cout = std::cerr; +namespace debug { + /// standard output for debug messages + std::ostream & _akantu_debug_cout = std::cerr; -/// standard output for normal messages -std::ostream & _akantu_cout = std::cout; + /// standard output for normal messages + std::ostream & _akantu_cout = std::cout; -/// debug level -DebugLevel _debug_level = (DebugLevel) 5; + /// debug level + DebugLevel _debug_level = (DebugLevel) 5; + + /// parallel context used in debug messages + std::string _parallel_context = ""; +}; /* -------------------------------------------------------------------------- */ __END_AKANTU__ diff --git a/synchronizer/communicator.cc b/synchronizer/communicator.cc index 886470ffb..4e821cee0 100644 --- a/synchronizer/communicator.cc +++ b/synchronizer/communicator.cc @@ -1,423 +1,453 @@ /** * @file communicator.cc * @author Nicolas Richart * @date Thu Aug 26 16:36:21 2010 * * @brief implementation of a communicator using a static_communicator for real * send/receive * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #include "communicator.hh" #include "static_communicator.hh" #include "mesh_utils.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ Communicator::Communicator(SynchronizerID id, MemoryID memory_id) : Synchronizer(id, memory_id), static_communicator(StaticCommunicator::getStaticCommunicator()) { AKANTU_DEBUG_IN(); for (UInt t = _not_defined; t < _max_element_type; ++t) { element_to_send_offset [t] = NULL; element_to_send [t] = NULL; element_to_receive_offset[t] = NULL; element_to_receive [t] = NULL; } AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ Communicator::~Communicator() { AKANTU_DEBUG_IN(); AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ Communicator * Communicator::createCommunicatorDistributeMesh(Mesh & mesh, const MeshPartition * partition, UInt root, SynchronizerID id, MemoryID memory_id) { AKANTU_DEBUG_IN(); StaticCommunicator * comm = StaticCommunicator::getStaticCommunicator(); UInt nb_proc = comm->getNbProc(); UInt my_rank = comm->whoAmI(); UInt * local_connectivity; UInt * local_partitions; Vector old_nodes; Vector * nodes = mesh.getNodesPointer(); UInt spatial_dimension = nodes->getNbComponent(); Communicator * communicator = new Communicator(); if(nb_proc == 1) return communicator; /* ------------------------------------------------------------------------ */ /* Local (rank == root) */ /* ------------------------------------------------------------------------ */ if(my_rank == root) { AKANTU_DEBUG_ASSERT(partition->getNbPartition() == nb_proc, "The number of partition does not match the number of processors"); /** * connectivity and communications scheme construction */ const Mesh::ConnectivityTypeList & type_list = mesh.getConnectivityTypeList(); Mesh::ConnectivityTypeList::const_iterator it; for(it = type_list.begin(); it != type_list.end(); ++it) { ElementType type = *it; if(Mesh::getSpatialDimension(type) != mesh.getSpatialDimension()) continue; UInt nb_nodes_per_element = Mesh::getNbNodesPerElement(type); UInt nb_element = mesh.getNbElement(*it); UInt nb_local_element[nb_proc]; UInt nb_ghost_element[nb_proc]; UInt nb_element_to_send[nb_proc]; memset(nb_local_element, 0, nb_proc*sizeof(UInt)); memset(nb_ghost_element, 0, nb_proc*sizeof(UInt)); memset(nb_element_to_send, 0, nb_proc*sizeof(UInt)); UInt * partition_num = partition->getPartition(type).values; UInt * ghost_partition = partition->getGhostPartition(type).values; UInt * ghost_partition_offset = partition->getGhostPartitionOffset(type).values; /// constricting the reordering structures for (UInt el = 0; el < nb_element; ++el) { nb_local_element[partition_num[el]]++; for (UInt part = ghost_partition_offset[el]; part < ghost_partition_offset[el + 1]; ++part) { nb_ghost_element[ghost_partition[part]]++; } nb_element_to_send[partition_num[el]] += ghost_partition_offset[el + 1] - ghost_partition_offset[el] + 1; } /// allocating buffers UInt * buffers[nb_proc]; UInt * buffers_tmp[nb_proc]; for (UInt p = 0; p < nb_proc; ++p) { UInt size = nb_nodes_per_element * (nb_local_element[p] + nb_ghost_element[p]); buffers[p] = new UInt[size]; buffers_tmp[p] = buffers[p]; } /// copying the local connectivity UInt * conn_val = mesh.getConnectivity(type).values; for (UInt el = 0; el < nb_element; ++el) { memcpy(buffers_tmp[partition_num[el]], conn_val + el * nb_nodes_per_element, nb_nodes_per_element * sizeof(UInt)); buffers_tmp[partition_num[el]] += nb_nodes_per_element; } /// copying the connectivity of ghost element //conn_val = mesh.getGhostConnectivity(type).values; for (UInt el = 0; el < nb_element; ++el) { for (UInt part = ghost_partition_offset[el]; part < ghost_partition_offset[el + 1]; ++part) { UInt proc = ghost_partition[part]; memcpy(buffers_tmp[proc], conn_val + el * nb_nodes_per_element, nb_nodes_per_element * sizeof(UInt)); buffers_tmp[proc] += nb_nodes_per_element; } } /// send all connectivity and ghost information to all processors - std::vector requests; + std::vector requests; for (UInt p = 0; p < nb_proc; ++p) { if(p != root) { UInt size[4]; size[0] = (UInt) type; size[1] = nb_local_element[p]; size[2] = nb_ghost_element[p]; size[3] = nb_element_to_send[p]; comm->send(size, 4, p, 0); + AKANTU_DEBUG_INFO("Sending connectivities to proc " << p); requests.push_back(comm->asyncSend(buffers[p], nb_nodes_per_element * (nb_local_element[p] + nb_ghost_element[p]), p, 1)); } else { local_connectivity = buffers[p]; } } /// create the renumbered connectivity + AKANTU_DEBUG_INFO("Renumbering local connectivities"); MeshUtils::renumberMeshNodes(mesh, local_connectivity, nb_local_element[root], nb_ghost_element[root], type, &old_nodes); comm->waitAll(requests); requests.clear(); for (UInt p = 0; p < nb_proc; ++p) { delete [] buffers[p]; } for (UInt p = 0; p < nb_proc; ++p) { buffers[p] = new UInt[nb_ghost_element[p] + nb_element_to_send[p]]; buffers_tmp[p] = buffers[p]; } /// splitting the partition information to send them to processors UInt count_by_proc[nb_proc]; memset(count_by_proc, 0, nb_proc*sizeof(UInt)); for (UInt el = 0; el < nb_element; ++el) { *(buffers_tmp[partition_num[el]]++) = ghost_partition_offset[el + 1] - ghost_partition_offset[el]; for (UInt part = ghost_partition_offset[el], i = 0; part < ghost_partition_offset[el + 1]; ++part, ++i) { *(buffers_tmp[partition_num[el]]++) = ghost_partition[part]; } } for (UInt el = 0; el < nb_element; ++el) { for (UInt part = ghost_partition_offset[el], i = 0; part < ghost_partition_offset[el + 1]; ++part, ++i) { *(buffers_tmp[ghost_partition[part]]++) = partition_num[el]; } } /// last data to compute the communication scheme for (UInt p = 0; p < nb_proc; ++p) { if(p != root) { + AKANTU_DEBUG_INFO("Sending partition informations to proc " << p); requests.push_back(comm->asyncSend(buffers[p], nb_element_to_send[p] + nb_ghost_element[p], p, 2)); } else { local_partitions = buffers[p]; } } + AKANTU_DEBUG_INFO("Creating communications scheme"); communicator->fillCommunicationScheme(local_partitions, nb_local_element[root], nb_ghost_element[root], nb_element_to_send[root], type); + comm->barrier(); + comm->waitAll(requests); + comm->freeCommunicationRequest(requests); requests.clear(); } + for (UInt p = 0; p < nb_proc; ++p) { + if(p != root) { + UInt size[4]; + size[0] = (UInt) _not_defined; + size[1] = 0; + size[2] = 0; + size[3] = 0; + comm->send(size, 4, p, 0); + } + } + /** * Nodes coordinate construction and synchronization */ /// get the list of nodes to send and send them Real * local_nodes; for (UInt p = 0; p < nb_proc; ++p) { UInt nb_nodes; UInt * buffer; if(p != root) { + AKANTU_DEBUG_INFO("Receiving list of nodes from proc " << p); comm->receive(&nb_nodes, 1, p, 0); buffer = new UInt[nb_nodes]; comm->receive(buffer, nb_nodes, p, 3); } else { nb_nodes = old_nodes.getSize(); buffer = old_nodes.values; } /// get the coordinates for the selected nodes Real * nodes_to_send = new Real[nb_nodes * spatial_dimension]; Real * nodes_to_send_tmp = nodes_to_send; for (UInt n = 0; n < nb_nodes; ++n) { memcpy(nodes_to_send_tmp, nodes->values + spatial_dimension * buffer[n], spatial_dimension * sizeof(Real)); nodes_to_send_tmp += spatial_dimension; } if(p != root) { /// send them for distant processors delete [] buffer; + AKANTU_DEBUG_INFO("Sending coordinates to proc " << p); comm->send(nodes_to_send, nb_nodes * spatial_dimension, p, 4); delete [] nodes_to_send; } else { /// save them for local processor local_nodes = nodes_to_send; } } /// construct the local nodes coordinates UInt nb_nodes = old_nodes.getSize(); nodes->resize(nb_nodes); memcpy(nodes->values, local_nodes, nb_nodes * spatial_dimension * sizeof(Real)); delete [] local_nodes; /* ---------------------------------------------------------------------- */ /* Distant (rank != root) */ /* ---------------------------------------------------------------------- */ } else { /** * connectivity and communications scheme construction on distant processors */ ElementType type = _not_defined; do { UInt size[4]; comm->receive(size, 4, root, 0); type = (ElementType) size[0]; UInt nb_local_element = size[1]; UInt nb_ghost_element = size[2]; UInt nb_element_to_send = size[3]; - UInt nb_nodes_per_element = Mesh::getNbNodesPerElement(type); if(type != _not_defined) { + UInt nb_nodes_per_element = Mesh::getNbNodesPerElement(type); + local_connectivity = new UInt[(nb_local_element + nb_ghost_element) * nb_nodes_per_element]; + AKANTU_DEBUG_INFO("Receiving connectivities from proc " << root); comm->receive(local_connectivity, nb_nodes_per_element * (nb_local_element + nb_ghost_element), root, 1); - + AKANTU_DEBUG_INFO("Renumbering local connectivities"); MeshUtils::renumberMeshNodes(mesh, local_connectivity, nb_local_element, nb_ghost_element, type, &old_nodes); delete [] local_connectivity; local_partitions = new UInt[nb_element_to_send + nb_ghost_element]; + AKANTU_DEBUG_INFO("Receiving partition informations from proc " << root); comm->receive(local_partitions, nb_element_to_send + nb_ghost_element, root, 2); + comm->barrier(); + + AKANTU_DEBUG_INFO("Creating communications scheme"); communicator->fillCommunicationScheme(local_partitions, nb_local_element, nb_ghost_element, nb_element_to_send, type); delete [] local_partitions; } } while(type != _not_defined); - /** * Nodes coordinate construction and synchronization on distant processors */ + AKANTU_DEBUG_INFO("Sending list of nodes from proc " << root); UInt nb_nodes = old_nodes.getSize(); comm->send(&nb_nodes, 1, root, 0); comm->send(old_nodes.values, nb_nodes, root, 3); nodes->resize(nb_nodes); + AKANTU_DEBUG_INFO("Receiving coordinates from proc " << root); comm->receive(nodes->values, nb_nodes * spatial_dimension, root, 4); } AKANTU_DEBUG_OUT(); return communicator; } /* -------------------------------------------------------------------------- */ void Communicator::fillCommunicationScheme(UInt * partition, UInt nb_local_element, UInt nb_ghost_element, UInt nb_element_to_send, ElementType type) { AKANTU_DEBUG_IN(); UInt nb_proc = static_communicator->getNbProc(); if(element_to_send[type]) { element_to_send_offset[type]->resize(nb_proc + 1); element_to_send[type]->resize(nb_element_to_send); } else { std::stringstream sstr; sstr << id << ":element_to_send"; - element_to_send[type] = &(alloc(sstr.str(), nb_element_to_send, 1)); + element_to_send[type] = &(alloc(sstr.str(), 0, 1)); sstr << "_offset"; element_to_send_offset[type] = &(alloc(sstr.str(), nb_proc + 1, 1)); } UInt * send_offset = element_to_send_offset[type]->values; memset(send_offset, 0, (nb_proc + 1) * sizeof(UInt)); UInt * part = partition; for (UInt lel = 0; lel < nb_local_element; ++lel) { UInt nb_send = *part++; for (UInt p = 0; p < nb_send; ++p) { send_offset[*part++]++; } } for (UInt i = 1; i < nb_proc; ++i) send_offset[i] += send_offset[i-1]; for (UInt i = nb_proc; i > 0; --i) send_offset[i] = send_offset[i-1]; send_offset[0] = 0; + element_to_send[type]->resize(send_offset[nb_proc]); + UInt * elem_to_send = element_to_send[type]->values; part = partition; for (UInt lel = 0; lel < nb_local_element; ++lel) { UInt nb_send = *part++; for (UInt p = 0; p < nb_send; ++p) { - elem_to_send[send_offset[*part++]] = lel; + elem_to_send[send_offset[*part++]++] = lel; } } for (UInt i = nb_proc; i > 0; --i) send_offset[i] = send_offset[i-1]; send_offset[0] = 0; - partition = part; /// finished with the local element, goes to the ghost part - if(element_to_receive[type]) { element_to_receive_offset[type]->resize(nb_proc + 1); element_to_receive[type]->resize(nb_ghost_element); } else { std::stringstream sstr; sstr << id << ":element_to_receive"; element_to_receive[type] = &(alloc(sstr.str(), nb_ghost_element, 1)); sstr << "_offset"; element_to_receive_offset[type] = &(alloc(sstr.str(), nb_proc + 1, 1)); } UInt * receive_offset = element_to_receive_offset[type]->values; memset(receive_offset, 0, (nb_proc + 1) * sizeof(UInt)); part = partition; for (UInt gel = 0; gel < nb_ghost_element; ++gel) { receive_offset[*part++]++; } for (UInt i = 1; i < nb_proc; ++i) receive_offset[i] += receive_offset[i-1]; for (UInt i = nb_proc; i > 0; --i) receive_offset[i] = receive_offset[i-1]; receive_offset[0] = 0; UInt * elem_to_receive = element_to_receive[type]->values; part = partition; - for (UInt lel = 0; lel < nb_local_element; ++lel) { - elem_to_receive[receive_offset[*part++]] = lel; + std::cout << "nb_ghost_element : " << nb_ghost_element; + + for (UInt lel = 0; lel < nb_ghost_element; ++lel) { + std::cout << "lel : " << lel << " " << *part << " - > " << receive_offset[*part] << std::endl; + elem_to_receive[receive_offset[*part++]++] = lel; } for (UInt i = nb_proc; i > 0; --i) receive_offset[i] = receive_offset[i-1]; receive_offset[0] = 0; AKANTU_DEBUG_OUT(); } /* -------------------------------------------------------------------------- */ __END_AKANTU__ diff --git a/synchronizer/static_communicator.cc b/synchronizer/static_communicator.cc index 073819b94..51bd517ae 100644 --- a/synchronizer/static_communicator.cc +++ b/synchronizer/static_communicator.cc @@ -1,59 +1,59 @@ /** * @file static_communicator.cc * @author Nicolas Richart * @date Thu Aug 19 15:39:47 2010 * * @brief implementation of the common part of the static communicator * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #include "static_communicator.hh" #ifdef AKANTU_USE_MPI # include "static_communicator_mpi.hh" #endif /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ bool StaticCommunicator::is_instantiated = false; StaticCommunicator * StaticCommunicator::static_communicator = NULL; /* -------------------------------------------------------------------------- */ StaticCommunicator * StaticCommunicator::getStaticCommunicator(CommunicatorType type) { AKANTU_DEBUG_IN(); #ifdef AKANTU_USE_MPI if(type == _communicator_mpi) if (!static_communicator) AKANTU_DEBUG_ERROR("You must call getStaticCommunicator(argc, argv) to create a MPI communicator"); #endif - if (!static_communicator) - static_communicator = new StaticCommunicator(); + // if (!static_communicator) + // static_communicator = new StaticCommunicator(); is_instantiated = true; AKANTU_DEBUG_OUT(); return static_communicator; } /* -------------------------------------------------------------------------- */ StaticCommunicator * StaticCommunicator::getStaticCommunicator(int * argc, char *** argv, CommunicatorType type) { #ifdef AKANTU_USE_MPI if(type == _communicator_mpi) if (!static_communicator) static_communicator = dynamic_cast(new StaticCommunicatorMPI(argc, argv)); #endif return getStaticCommunicator(type); } __END_AKANTU__ diff --git a/synchronizer/static_communicator.hh b/synchronizer/static_communicator.hh index 46004e974..ae0be4e4d 100644 --- a/synchronizer/static_communicator.hh +++ b/synchronizer/static_communicator.hh @@ -1,99 +1,107 @@ /** * @file static_communicator.hh * @author Nicolas Richart * @date Thu Aug 19 15:34:09 2010 * * @brief Class handling the parallel communications * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_STATIC_COMMUNICATOR_HH__ #define __AKANTU_STATIC_COMMUNICATOR_HH__ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ class CommunicationRequest { - +public: + virtual ~CommunicationRequest() {}; }; class StaticCommunicator { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ protected: StaticCommunicator() { }; public: virtual ~StaticCommunicator() { }; /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: - virtual void send(UInt * buffer, Int size, Int receiver, Int tag) { }; - virtual void send(Real * buffer, Int size, Int receiver, Int tag) { }; + virtual void send(UInt * buffer, Int size, Int receiver, Int tag) = 0; + virtual void send(Real * buffer, Int size, Int receiver, Int tag) = 0; + + virtual void receive(UInt * buffer, Int size, Int sender, Int tag) = 0; + virtual void receive(Real * buffer, Int size, Int sender, Int tag) = 0; + + virtual CommunicationRequest * asyncSend(UInt * buffer, Int size, + Int receiver, Int tag) = 0; + // { + // return new CommunicationRequest(); }; + virtual CommunicationRequest * asyncSend(Real * buffer, Int size, + Int receiver, Int tag) = 0; + // { + // return new CommunicationRequest(); + // }; - virtual void receive(UInt * buffer, Int size, Int sender, Int tag) { }; - virtual void receive(Real * buffer, Int size, Int sender, Int tag) { }; + virtual void wait(CommunicationRequest * request) = 0; - virtual CommunicationRequest asyncSend(UInt * buffer, Int size, - Int receiver, Int tag) { - return CommunicationRequest(); }; - virtual CommunicationRequest asyncSend(Real * buffer, Int size, - Int receiver, Int tag) { - return CommunicationRequest(); }; + virtual void waitAll(std::vector & requests) = 0; - virtual void wait(CommunicationRequest & request) {}; + virtual void freeCommunicationRequest(CommunicationRequest * request) = 0; + virtual void freeCommunicationRequest(std::vector & requests) = 0; - virtual void waitAll(std::vector & requests) {}; + virtual void barrier() = 0; /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: + virtual Int getNbProc() = 0; + virtual Int whoAmI() = 0; + static StaticCommunicator * getStaticCommunicator(CommunicatorType type = _communicator_mpi); static StaticCommunicator * getStaticCommunicator(int * argc, char *** argv, CommunicatorType type = _communicator_mpi); static bool isInstantiated() { return is_instantiated; }; - - virtual Int getNbProc() { return 1; }; - - virtual Int whoAmI() { return 0; }; /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: static bool is_instantiated; static StaticCommunicator * static_communicator; protected: Int prank; Int psize; }; /* -------------------------------------------------------------------------- */ /* inline functions */ /* -------------------------------------------------------------------------- */ //#include "static_communicator_inline_impl.cc" __END_AKANTU__ #endif /* __AKANTU_STATIC_COMMUNICATOR_HH__ */ diff --git a/synchronizer/static_communicator_mpi.hh b/synchronizer/static_communicator_mpi.hh index aa9bcd3c5..c9b59fcae 100644 --- a/synchronizer/static_communicator_mpi.hh +++ b/synchronizer/static_communicator_mpi.hh @@ -1,94 +1,101 @@ /** * @file static_communicator_mpi.hh * @author Nicolas Richart * @date Thu Sep 2 19:59:58 2010 * * @brief class handling parallel communication trough MPI * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #ifndef __AKANTU_STATIC_COMMUNICATOR_MPI_HH__ #define __AKANTU_STATIC_COMMUNICATOR_MPI_HH__ /* -------------------------------------------------------------------------- */ #include /* -------------------------------------------------------------------------- */ #include "static_communicator.hh" /* -------------------------------------------------------------------------- */ __BEGIN_AKANTU__ /* -------------------------------------------------------------------------- */ class CommunicationRequestMPI : public CommunicationRequest { public: - MPI_Request & getMPIRequest() { return request; }; + inline CommunicationRequestMPI(); + inline ~CommunicationRequestMPI(); + inline MPI_Request * getMPIRequest() { return request; }; private: - MPI_Request request; + MPI_Request * request; }; /* -------------------------------------------------------------------------- */ -class StaticCommunicatorMPI : public StaticCommunicator { +class StaticCommunicatorMPI : public virtual StaticCommunicator { /* ------------------------------------------------------------------------ */ /* Constructors/Destructors */ /* ------------------------------------------------------------------------ */ public: inline StaticCommunicatorMPI(int * argc, char *** argv); inline virtual ~StaticCommunicatorMPI(); /* ------------------------------------------------------------------------ */ /* Methods */ /* ------------------------------------------------------------------------ */ public: inline void send(UInt * buffer, Int size, Int receiver, Int tag); inline void send(Real * buffer, Int size, Int receiver, Int tag); inline void receive(UInt * buffer, Int size, Int sender, Int tag); inline void receive(Real * buffer, Int size, Int sender, Int tag); - inline CommunicationRequest asyncSend(UInt * buffer, Int size, Int receiver, Int tag); - inline CommunicationRequest asyncSend(Real * buffer, Int size, Int receiver, Int tag); + inline CommunicationRequest * asyncSend(UInt * buffer, Int size, Int receiver, Int tag); + inline CommunicationRequest * asyncSend(Real * buffer, Int size, Int receiver, Int tag); - inline void wait(CommunicationRequest & request); + inline void wait(CommunicationRequest * request); - inline void waitAll(std::vector & requests); + inline void waitAll(std::vector & requests); + inline void freeCommunicationRequest(CommunicationRequest * request); + inline void freeCommunicationRequest(std::vector & requests); + + inline void barrier(); + /* ------------------------------------------------------------------------ */ /* Accessors */ /* ------------------------------------------------------------------------ */ public: - inline Int getNbProc() { return psize; }; + inline void setMPIComm(MPI_Comm comm); + inline Int getNbProc() { return psize; }; inline Int whoAmI() { return prank; }; - inline void setMPIComm(MPI_Comm comm); /* ------------------------------------------------------------------------ */ /* Class Members */ /* ------------------------------------------------------------------------ */ private: MPI_Comm communicator; }; /* -------------------------------------------------------------------------- */ /* inline functions */ /* -------------------------------------------------------------------------- */ #include "static_communicator_mpi_inline_impl.cc" __END_AKANTU__ #endif /* __AKANTU_STATIC_COMMUNICATOR_MPI_HH__ */ diff --git a/synchronizer/static_communicator_mpi_inline_impl.cc b/synchronizer/static_communicator_mpi_inline_impl.cc index 9160885b5..641df4264 100644 --- a/synchronizer/static_communicator_mpi_inline_impl.cc +++ b/synchronizer/static_communicator_mpi_inline_impl.cc @@ -1,98 +1,126 @@ /** * @file static_communicator_mpi_inline_impl.hh * @author Nicolas Richart * @date Thu Sep 2 15:10:51 2010 * * @brief implementation of the mpi communicator * * @section LICENSE * * * */ +/* -------------------------------------------------------------------------- */ +inline CommunicationRequestMPI::CommunicationRequestMPI() { + request = new MPI_Request; +} + +/* -------------------------------------------------------------------------- */ +inline CommunicationRequestMPI::~CommunicationRequestMPI() { + delete request; +} + /* -------------------------------------------------------------------------- */ inline StaticCommunicatorMPI::StaticCommunicatorMPI(int * argc, char *** argv) { MPI_Init(argc, argv); setMPIComm(MPI_COMM_WORLD); }; /* -------------------------------------------------------------------------- */ inline StaticCommunicatorMPI::~StaticCommunicatorMPI() { MPI_Finalize(); }; /* -------------------------------------------------------------------------- */ inline void StaticCommunicatorMPI::setMPIComm(MPI_Comm comm) { communicator = comm; MPI_Comm_rank(communicator, &prank); MPI_Comm_size(communicator, &psize); } /* -------------------------------------------------------------------------- */ inline void StaticCommunicatorMPI::send(UInt * buffer, Int size, Int receiver, Int tag) { Int ret = MPI_Send(buffer, size, MPI_UNSIGNED, receiver, tag, communicator); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Send."); } /* -------------------------------------------------------------------------- */ inline void StaticCommunicatorMPI::send(Real * buffer, Int size, Int receiver, Int tag) { Int ret = MPI_Send(buffer, size, MPI_DOUBLE, receiver, tag, communicator); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Send."); } /* -------------------------------------------------------------------------- */ inline void StaticCommunicatorMPI::receive(UInt * buffer, Int size, Int sender, Int tag) { MPI_Status status; Int ret = MPI_Recv(buffer, size, MPI_UNSIGNED, sender, tag, communicator, &status); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Recv."); } /* -------------------------------------------------------------------------- */ inline void StaticCommunicatorMPI::receive(Real * buffer, Int size, Int sender, Int tag) { MPI_Status status; Int ret = MPI_Recv(buffer, size, MPI_DOUBLE, sender, tag, communicator, &status); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Recv."); } /* -------------------------------------------------------------------------- */ -inline CommunicationRequest StaticCommunicatorMPI::asyncSend(UInt * buffer, Int size, +inline CommunicationRequest * StaticCommunicatorMPI::asyncSend(UInt * buffer, Int size, Int receiver, Int tag) { - CommunicationRequestMPI request; - Int ret = MPI_Isend(buffer, size, MPI_UNSIGNED, receiver, tag, communicator, &(request.getMPIRequest())); + CommunicationRequestMPI * request = new CommunicationRequestMPI(); + Int ret = MPI_Isend(buffer, size, MPI_UNSIGNED, receiver, tag, communicator, request->getMPIRequest()); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Isend."); return request; }; /* -------------------------------------------------------------------------- */ -inline CommunicationRequest StaticCommunicatorMPI::asyncSend(Real * buffer, Int size, +inline CommunicationRequest * StaticCommunicatorMPI::asyncSend(Real * buffer, Int size, Int receiver, Int tag) { - CommunicationRequestMPI request; - Int ret = MPI_Isend(buffer, size, MPI_DOUBLE, receiver, tag, communicator, &(request.getMPIRequest())); + CommunicationRequestMPI * request = new CommunicationRequestMPI(); + Int ret = MPI_Isend(buffer, size, MPI_DOUBLE, receiver, tag, communicator, request->getMPIRequest()); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Isend."); return request; }; /* -------------------------------------------------------------------------- */ -inline void StaticCommunicatorMPI::wait(CommunicationRequest & request) { +inline void StaticCommunicatorMPI::wait(CommunicationRequest * request) { MPI_Status status; - CommunicationRequestMPI & req_mpi = static_cast(request); - MPI_Request * req = &(req_mpi.getMPIRequest()); + CommunicationRequestMPI * req_mpi = static_cast(request); + MPI_Request * req = req_mpi->getMPIRequest(); Int ret = MPI_Wait(req, &status); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_WAIT."); } /* -------------------------------------------------------------------------- */ -inline void StaticCommunicatorMPI::waitAll(std::vector & requests) { +inline void StaticCommunicatorMPI::waitAll(std::vector & requests) { MPI_Status status; - std::vector::iterator it; + std::vector::iterator it; for(it = requests.begin(); it != requests.end(); ++it) { - MPI_Request * req = &(static_cast(*it).getMPIRequest()); + MPI_Request * req = static_cast(*it)->getMPIRequest(); Int ret = MPI_Wait(req, &status); AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_WAIT."); } } + +/* -------------------------------------------------------------------------- */ +inline void StaticCommunicatorMPI::freeCommunicationRequest(CommunicationRequest * request) { + delete request; +} + +/* -------------------------------------------------------------------------- */ +inline void StaticCommunicatorMPI::freeCommunicationRequest(std::vector & requests) { + std::vector::iterator it; + for(it = requests.begin(); it != requests.end(); ++it) { + delete (*it); + } +} + +/* -------------------------------------------------------------------------- */ +inline void StaticCommunicatorMPI::barrier() { + MPI_Barrier(communicator); +} diff --git a/synchronizer/static_communicator_mpi_inline_impl.hh b/synchronizer/static_communicator_mpi_inline_impl.hh deleted file mode 100644 index dc07b1c2a..000000000 --- a/synchronizer/static_communicator_mpi_inline_impl.hh +++ /dev/null @@ -1,93 +0,0 @@ -/** - * @file static_communicator_mpi_inline_impl.hh - * @author Nicolas Richart - * @date Thu Sep 2 15:10:51 2010 - * - * @brief implementation of the mpi communicator - * - * @section LICENSE - * - * - * - */ - -/* -------------------------------------------------------------------------- */ -inline StaticCommunicatorMPI::StaticCommunicatorMPI(int * argc, char *** argv) { - MPI_Init(argc, argv); - setMPIComm(MPI_COMM_WORLD); -}; - -/* -------------------------------------------------------------------------- */ -inline StaticCommunicatorMPI::~StaticCommunicatorMPI() { - MPI_Finalize(); -}; - -/* -------------------------------------------------------------------------- */ -inline void StaticCommunicatorMPI::setMPIComm(MPI_Comm comm) { - communicator = comm; - MPI_Comm_rank(comm, &prank); - MPI_Comm_size(comm, &psize); -} - -/* -------------------------------------------------------------------------- */ -inline void StaticCommunicatorMPI::send(UInt * buffer, UInt size, - UInt receiver, UInt tag) { - int ret = MPI_Send(buffer, size, MPI_UNSIGNED, receiver, tag, comm); - AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Send."); -} - -/* -------------------------------------------------------------------------- */ -inline void StaticCommunicatorMPI::send(Real * buffer, UInt size, - UInt receiver, UInt tag) { - int ret = MPI_Send(buffer, size, MPI_DOUBLE, receiver, tag, comm); - AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Send."); -} - -/* -------------------------------------------------------------------------- */ -inline void StaticCommunicatorMPI::receive(UInt * buffer, UInt size, - UInt sender, UInt tag) { - MPI_Status status; - int ret = MPI_Recv(buffer, size, MPI_UNSIGNED, sender, tag, comm, &status); - AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Recv."); -} - -/* -------------------------------------------------------------------------- */ -inline void StaticCommunicatorMPI::receive(Real * buffer, UInt size, - UInt sender, UInt tag) { - MPI_Status status; - int ret = MPI_Recv(buffer, size, MPI_DOUBLE, sender, tag, comm, &status); - AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Recv."); -} - -/* -------------------------------------------------------------------------- */ -inline CommunicationRequest StaticCommunicatorMPI::asyncSend(UInt * buffer, UInt size, UInt receiver, UInt tag) { - CommunicationRequestMPI request; - int ret = MPI_Isend(buffer, size, MPI_UNSIGNED, receiver, tag, comm, &(request.getMPIRequest())); - AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Isend."); - return request; -}; - -/* -------------------------------------------------------------------------- */ -inline CommunicationRequest StaticCommunicatorMPI::asyncSend(Real * buffer, UInt size, UInt receiver, UInt tag) { - CommunicationRequestMPI request; - int ret = MPI_Isend(buffer, size, MPI_DOUBLE, receiver, tag, comm, &(request.getMPIRequest())); - AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_Isend."); - return request; -}; - -/* -------------------------------------------------------------------------- */ -inline void StaticCommunicatorMPI::wait(const CommunicationRequest & request) { - MPI_Status status; - int ret = MPI_Wait(&(request.getMPIRequest()), &status); - AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_WAIT."); -} - -/* -------------------------------------------------------------------------- */ -inline void StaticCommunicatorMPI::waitAll(const std::vector & requests) { - MPI_Status status; - std::vector::const_iterator it; - for(it = requests.begin(); it != requests.end(); ++it) { - int ret = MPI_Wait(&(*it->getMPIRequest()), &status); - AKANTU_DEBUG_ASSERT(ret == MPI_SUCCESS, "Error in MPI_WAIT."); - } -} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 178f9690f..bbe91c2eb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,102 +1,89 @@ #=============================================================================== # @file CMakeLists.txt # @author Nicolas Richart # @author Guillaume Anciaux # @date Fri Jun 11 09:46:59 2010 # # @section LICENSE # # # # @section DESCRIPTION # #=============================================================================== #=============================================================================== # Tests #=============================================================================== -option(BUILD_ALL_TESTS "Build all tests") +option(AKANTU_BUILD_ALL_TESTS "Build all tests") -macro(REGISTER_TEST test_name source_list) +#=============================================================================== +macro(register_test test_name source_list) add_executable(${test_name} ${source_list}) target_link_libraries(${test_name} akantu ${AKANTU_EXTERNAL_LIBRARIES}) endmacro() +#=============================================================================== macro(add_mesh MESH_TARGET GEO_FILE DIM ORDER) set(_geo_file ${CMAKE_CURRENT_SOURCE_DIR}/${GEO_FILE}) get_filename_component(_msh_file "${GEO_FILE}" NAME_WE) set(_msh_file ${CMAKE_CURRENT_BINARY_DIR}/${_msh_file}.msh) if(EXISTS ${_geo_file}) add_custom_command( OUTPUT ${_msh_file} DEPENDS ${_geo_file} COMMAND gmsh ARGS -${DIM} -order ${ORDER} -optimize -o ${_msh_file} ${_geo_file} 2>&1 > /dev/null ) add_custom_target(${MESH_TARGET} DEPENDS ${_msh_file}) else(EXISTS ${_geo_file}) message(FATAL_ERROR "File ${_geo_file} not found") endif(EXISTS ${_geo_file}) endmacro() - -macro(ADD_EXAMPLE example_name desc) +#=============================================================================== +macro(add_example example_name desc) string(TOUPPER ${example_name} upper_name) - set(AKANTU_UNIT_TESTS "") - option(BUILD_${upper_name} "${desc}") - if(BUILD_ALL_TESTS) - set(BUILD_${upper_name}_OLD ${BUILD_${upper_name}} CACHE INTERNAL "${desc}" FORCE) - set(BUILD_${upper_name} ON CACHE INTERNAL "${desc}" FORCE) - else(BUILD_ALL_TESTS) - if(DEFINED BUILD_${upper_name}_OLD) - set(BUILD_${upper_name} ${BUILD_${upper_name}_OLD} CACHE BOOL "${desc}" FORCE) - unset(BUILD_${upper_name}_OLD CACHE) - endif(DEFINED BUILD_${upper_name}_OLD) - endif(BUILD_ALL_TESTS) - if(BUILD_${upper_name}) + option(AKANTU_BUILD_${upper_name} "${desc}") + mark_as_advanced(AKANTU_BUILD_${upper_name}) + + if(AKANTU_BUILD_ALL_TESTS) + set(AKANTU_BUILD_${upper_name}_OLD + ${AKANTU_BUILD_${upper_name}} + CACHE INTERNAL "${desc}" FORCE) + + set(AKANTU_BUILD_${upper_name} ON + CACHE INTERNAL "${desc}" FORCE) + else(AKANTU_BUILD_ALL_TESTS) + if(DEFINED AKANTU_BUILD_${upper_name}_OLD) + set(AKANTU_BUILD_${upper_name} + ${AKANTU_BUILD_${upper_name}_OLD} + CACHE BOOL "${desc}" FORCE) + + unset(BUILD_${upper_name}_OLD + CACHE) + endif(DEFINED AKANTU_BUILD_${upper_name}_OLD) + endif(AKANTU_BUILD_ALL_TESTS) + + if(AKANTU_BUILD_${upper_name}) add_subdirectory(${example_name}) - endif(BUILD_${upper_name}) -endmacro() + endif(AKANTU_BUILD_${upper_name}) +endmacro() +#=============================================================================== +# List of tests +#=============================================================================== add_example(test_facet_extraction "Test mesh utils facet extraction") add_example(test_fem "Test finite element functionalties") add_example(test_mesh_io "Test mesh io object") add_example(test_solid_mechanics_model "Test solid mechanics object") add_example(test_static_memory "Test static memory") add_example(test_vector "Test akantu vector") + if(AKANTU_USE_SCOTCH AND SCOTCH_FOUND) -add_example(test_mesh_partitionate "Test mesh partition creation") + add_example(test_mesh_partitionate "Test mesh partition creation") endif(AKANTU_USE_SCOTCH AND SCOTCH_FOUND) - - -#set(AKANTU_UNIT_TESTS -# test/test_static_memory.cc -# test/test_mesh_io_msh.cc -# test/test_vector.cc -# test/test_fem.cc -# test/test_solid_mechanics_model.cc -# test/test_solid_mechanics_model_cube3d.cc -# test/test_solid_mechanics_model_bar_traction2d.cc -# test/test_facet_extraction_triangle1.cc -# test/test_facet_extraction_tetra1.cc -# test/test_interpolate_line_1.cc -# test/test_interpolate_triangle_1.cc -# test/test_interpolate_tetrahedra_1.cc -# ) -# -#if(AKANTU_USE_SCOTCH AND SCOTCH_FOUND) -# set(AKANTU_UNIT_TESTS -# ${AKANTU_UNIT_TESTS} -# test/test_mesh_partitionate.cc -# ) -#endif(AKANTU_USE_SCOTCH AND SCOTCH_FOUND) -# -#foreach(_test ${AKANTU_UNIT_TESTS}) -# get_filename_component(_target "${_test}" NAME_WE) -# add_executable(${_target} ${_test}) -# target_link_libraries(${_target} akantu ${AKANTU_EXTERNAL_LIBRARIES}) -#endforeach(_test) diff --git a/test/test_fem/test_gradient_line_1.cc b/test/test_fem/test_gradient_line_1.cc index 76205d13f..2fc0d03eb 100644 --- a/test/test_fem/test_gradient_line_1.cc +++ b/test/test_fem/test_gradient_line_1.cc @@ -1,69 +1,69 @@ /** * @file fem.cc * @author Nicolas Richart * @date Mon Jul 19 10:55:49 2010 * * @brief test of the fem class * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "fem.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { MeshIOMSH mesh_io; Mesh my_mesh(1); mesh_io.read("line.msh", my_mesh); FEM *fem = new FEM(my_mesh,1,"my_fem"); - _debug_level = dblDump; + debug::setDebugLevel(dblDump); fem->initShapeFunctions(); std::cout << *fem << std::endl; StaticMemory * st_mem = StaticMemory::getStaticMemory(); std::cout << *st_mem << std::endl; Vector const_val(fem->getMesh().getNbNodes(), 2, "const_val"); Vector grad_on_quad(0, 2, "grad_on_quad"); for (UInt i = 0; i < const_val.getSize(); ++i) { const_val.values[i * 2 + 0] = 1.; const_val.values[i * 2 + 1] = 2.; } fem->gradientOnQuadraturePoints(const_val, grad_on_quad, 2, _line_1); std::ofstream my_file("out.txt"); my_file << const_val << std::endl; my_file << grad_on_quad << std::endl; // interpolate coordinates Vector grad_coord_on_quad(0, 1, "coord_on_quad"); fem->gradientOnQuadraturePoints(my_mesh.getNodes(), grad_coord_on_quad, my_mesh.getSpatialDimension(), _line_1); my_file << my_mesh.getNodes() << std::endl; my_file << grad_coord_on_quad << std::endl; // delete fem; // finalize(); return EXIT_SUCCESS; } diff --git a/test/test_fem/test_gradient_tetrahedra_1.cc b/test/test_fem/test_gradient_tetrahedra_1.cc index 85efb4d69..d6b18945b 100644 --- a/test/test_fem/test_gradient_tetrahedra_1.cc +++ b/test/test_fem/test_gradient_tetrahedra_1.cc @@ -1,69 +1,69 @@ /** * @file fem.cc * @author Nicolas Richart * @date Mon Jul 19 10:55:49 2010 * * @brief test of the fem class * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "fem.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { MeshIOMSH mesh_io; Mesh my_mesh(3); mesh_io.read("cube.msh", my_mesh); FEM *fem = new FEM(my_mesh,3,"my_fem"); - _debug_level = dblDump; + debug::setDebugLevel(dblDump); fem->initShapeFunctions(); std::cout << *fem << std::endl; StaticMemory * st_mem = StaticMemory::getStaticMemory(); std::cout << *st_mem << std::endl; Vector const_val(fem->getMesh().getNbNodes(), 2, "const_val"); Vector grad_on_quad(0, 2*3, "grad_on_quad"); for (UInt i = 0; i < const_val.getSize(); ++i) { const_val.values[i * 2 + 0] = 1.; const_val.values[i * 2 + 1] = 2.; } fem->gradientOnQuadraturePoints(const_val, grad_on_quad, 2, _tetrahedra_1); std::ofstream my_file("out.txt"); my_file << const_val << std::endl; my_file << grad_on_quad << std::endl; // compute gradient of coordinates Vector grad_coord_on_quad(0, 9, "grad_coord_on_quad"); fem->gradientOnQuadraturePoints(my_mesh.getNodes(), grad_coord_on_quad, my_mesh.getSpatialDimension(), _tetrahedra_1); my_file << my_mesh.getNodes() << std::endl; my_file << grad_coord_on_quad << std::endl; // delete fem; // finalize(); return EXIT_SUCCESS; } diff --git a/test/test_fem/test_gradient_triangle_1.cc b/test/test_fem/test_gradient_triangle_1.cc index 61b842353..a926c89af 100644 --- a/test/test_fem/test_gradient_triangle_1.cc +++ b/test/test_fem/test_gradient_triangle_1.cc @@ -1,69 +1,69 @@ /** * @file fem.cc * @author Nicolas Richart * @date Mon Jul 19 10:55:49 2010 * * @brief test of the fem class * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "fem.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { MeshIOMSH mesh_io; Mesh my_mesh(2); mesh_io.read("triangle.msh", my_mesh); FEM *fem = new FEM(my_mesh,2,"my_fem"); - _debug_level = dblDump; + debug::setDebugLevel(dblDump); fem->initShapeFunctions(); std::cout << *fem << std::endl; StaticMemory * st_mem = StaticMemory::getStaticMemory(); std::cout << *st_mem << std::endl; Vector const_val(fem->getMesh().getNbNodes(), 2, "const_val"); Vector grad_on_quad(0, 2*2, "grad_on_quad"); for (UInt i = 0; i < const_val.getSize(); ++i) { const_val.values[i * 2 + 0] = 1.; const_val.values[i * 2 + 1] = 2.; } fem->gradientOnQuadraturePoints(const_val, grad_on_quad, 2, _triangle_1); std::ofstream my_file("out.txt"); my_file << const_val << std::endl; my_file << grad_on_quad << std::endl; // compute gradient of coordinates Vector grad_coord_on_quad(0, 4, "grad_coord_on_quad"); fem->gradientOnQuadraturePoints(my_mesh.getNodes(), grad_coord_on_quad, my_mesh.getSpatialDimension(), _triangle_1); my_file << my_mesh.getNodes() << std::endl; my_file << grad_coord_on_quad << std::endl; // delete fem; // finalize(); return EXIT_SUCCESS; } diff --git a/test/test_fem/test_interpolate_line_1.cc b/test/test_fem/test_interpolate_line_1.cc index a66d066aa..25bea5a5f 100644 --- a/test/test_fem/test_interpolate_line_1.cc +++ b/test/test_fem/test_interpolate_line_1.cc @@ -1,69 +1,69 @@ /** * @file fem.cc * @author Nicolas Richart * @date Mon Jul 19 10:55:49 2010 * * @brief test of the fem class * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "fem.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { MeshIOMSH mesh_io; Mesh my_mesh(1); mesh_io.read("line.msh", my_mesh); FEM *fem = new FEM(my_mesh,1,"my_fem"); - _debug_level = dblDump; + debug::setDebugLevel(dblDump); fem->initShapeFunctions(); std::cout << *fem << std::endl; StaticMemory * st_mem = StaticMemory::getStaticMemory(); std::cout << *st_mem << std::endl; Vector const_val(fem->getMesh().getNbNodes(), 2, "const_val"); Vector val_on_quad(0, 2, "val_on_quad"); for (UInt i = 0; i < const_val.getSize(); ++i) { const_val.values[i * 2 + 0] = 1.; const_val.values[i * 2 + 1] = 2.; } fem->interpolateOnQuadraturePoints(const_val, val_on_quad, 2, _line_1); std::ofstream my_file("out.txt"); my_file << const_val << std::endl; my_file << val_on_quad << std::endl; // interpolate coordinates Vector coord_on_quad(0, 1, "coord_on_quad"); fem->interpolateOnQuadraturePoints(my_mesh.getNodes(), coord_on_quad, my_mesh.getSpatialDimension(), _line_1); my_file << my_mesh.getNodes() << std::endl; my_file << coord_on_quad << std::endl; // delete fem; // finalize(); return EXIT_SUCCESS; } diff --git a/test/test_fem/test_interpolate_tetrahedra_1.cc b/test/test_fem/test_interpolate_tetrahedra_1.cc index 2a14fd268..a0f9f0bab 100644 --- a/test/test_fem/test_interpolate_tetrahedra_1.cc +++ b/test/test_fem/test_interpolate_tetrahedra_1.cc @@ -1,66 +1,66 @@ /** * @file fem.cc * @author Nicolas Richart * @date Mon Jul 19 10:55:49 2010 * * @brief test of the fem class * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "fem.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { MeshIOMSH mesh_io; Mesh my_mesh(3); mesh_io.read("cube.msh", my_mesh); FEM *fem = new FEM(my_mesh,3,"my_fem"); - _debug_level = dblDump; + debug::setDebugLevel(dblDump); fem->initShapeFunctions(); std::cout << *fem << std::endl; StaticMemory * st_mem = StaticMemory::getStaticMemory(); std::cout << *st_mem << std::endl; Vector const_val(fem->getMesh().getNbNodes(), 2, "const_val"); Vector val_on_quad(0, 2, "val_on_quad"); for (UInt i = 0; i < const_val.getSize(); ++i) { const_val.values[i * 2 + 0] = 1.; const_val.values[i * 2 + 1] = 2.; } fem->interpolateOnQuadraturePoints(const_val, val_on_quad, 2, _tetrahedra_1); std::ofstream my_file("out.txt"); my_file << const_val << std::endl; my_file << val_on_quad << std::endl; // interpolate coordinates Vector coord_on_quad(0, my_mesh.getSpatialDimension(), "coord_on_quad"); fem->interpolateOnQuadraturePoints(my_mesh.getNodes(), coord_on_quad, my_mesh.getSpatialDimension(), _tetrahedra_1); my_file << my_mesh.getNodes() << std::endl; my_file << coord_on_quad << std::endl; // delete fem; // finalize(); return EXIT_SUCCESS; } diff --git a/test/test_fem/test_interpolate_triangle_1.cc b/test/test_fem/test_interpolate_triangle_1.cc index cb927a047..fe4590455 100644 --- a/test/test_fem/test_interpolate_triangle_1.cc +++ b/test/test_fem/test_interpolate_triangle_1.cc @@ -1,66 +1,66 @@ /** * @file fem.cc * @author Nicolas Richart * @date Mon Jul 19 10:55:49 2010 * * @brief test of the fem class * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ #include #include /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "fem.hh" #include "mesh.hh" #include "mesh_io.hh" #include "mesh_io_msh.hh" /* -------------------------------------------------------------------------- */ using namespace akantu; int main(int argc, char *argv[]) { MeshIOMSH mesh_io; Mesh my_mesh(2); mesh_io.read("triangle.msh", my_mesh); FEM *fem = new FEM(my_mesh,2,"my_fem"); - _debug_level = dblDump; + debug::setDebugLevel(dblDump); fem->initShapeFunctions(); std::cout << *fem << std::endl; StaticMemory * st_mem = StaticMemory::getStaticMemory(); std::cout << *st_mem << std::endl; Vector const_val(fem->getMesh().getNbNodes(), 2, "const_val"); Vector val_on_quad(0, 2, "val_on_quad"); for (UInt i = 0; i < const_val.getSize(); ++i) { const_val.values[i * 2 + 0] = 1.; const_val.values[i * 2 + 1] = 2.; } fem->interpolateOnQuadraturePoints(const_val, val_on_quad, 2, _triangle_1); std::ofstream my_file("out.txt"); my_file << const_val << std::endl; my_file << val_on_quad << std::endl; // interpolate coordinates Vector coord_on_quad(0, my_mesh.getSpatialDimension(), "coord_on_quad"); fem->interpolateOnQuadraturePoints(my_mesh.getNodes(), coord_on_quad, my_mesh.getSpatialDimension(), _triangle_1); my_file << my_mesh.getNodes() << std::endl; my_file << coord_on_quad << std::endl; // delete fem; // finalize(); return EXIT_SUCCESS; } diff --git a/test/test_mesh_partitionate/CMakeLists.txt b/test/test_mesh_partitionate/CMakeLists.txt index 3f52fc064..c7a49900b 100644 --- a/test/test_mesh_partitionate/CMakeLists.txt +++ b/test/test_mesh_partitionate/CMakeLists.txt @@ -1,14 +1,19 @@ #=============================================================================== # @file CMakeLists.txt # @author Guillaume Anciaux # @date Fri Jun 11 09:46:59 2010 # # @section LICENSE # # # # @section DESCRIPTION # #=============================================================================== -REGISTER_TEST(test_mesh_partitionate test_mesh_partitionate.cc) +register_test(test_mesh_partitionate_scotch + test_mesh_partitionate.cc) +add_mesh(test_mesh_partitionate_mesh + triangle.geo 2 1) +add_dependencies(test_mesh_partitionate_scotch + test_mesh_partitionate_mesh) \ No newline at end of file diff --git a/test/test_mesh_partitionate/test_mesh_partitionate.cc b/test/test_mesh_partitionate/test_mesh_partitionate.cc index 8fab587bf..91bcc297a 100644 --- a/test/test_mesh_partitionate/test_mesh_partitionate.cc +++ b/test/test_mesh_partitionate/test_mesh_partitionate.cc @@ -1,78 +1,82 @@ /** * @file test_facet_extraction.cc * @author Guillaume ANCIAUX * @date Thu Aug 19 13:05:27 2010 * * @brief test of internal facet extraction * * @section LICENSE * * * */ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ #include "aka_common.hh" #include "static_communicator.hh" #include "communicator.hh" #include "mesh.hh" #include "mesh_io_msh.hh" #include "mesh_partition_scotch.hh" /* -------------------------------------------------------------------------- */ #ifdef AKANTU_USE_IOHELPER # include "io_helper.h" #endif //AKANTU_USE_IOHELPER int main(int argc, char *argv[]) { akantu::initialize(&argc, &argv); int dim = 2; akantu::ElementType type = akantu::_triangle_1; akantu::Mesh mesh(dim); akantu::StaticCommunicator * comm = akantu::StaticCommunicator::getStaticCommunicator(); akantu::Int psize = comm->getNbProc(); akantu::Int prank = comm->whoAmI(); akantu::Communicator * communicator; if(prank == 0) { akantu::MeshIOMSH mesh_io; mesh_io.read("triangle.msh", mesh); akantu::MeshPartition * partition = new akantu::MeshPartitionScotch(mesh, dim); partition->partitionate(psize); communicator = akantu::Communicator::createCommunicatorDistributeMesh(mesh, partition); delete partition; } else { communicator = akantu::Communicator::createCommunicatorDistributeMesh(mesh, NULL); } + comm->barrier(); + delete communicator; #ifdef AKANTU_USE_IOHELPER unsigned int nb_nodes = mesh.getNbNodes(); unsigned int nb_element = mesh.getNbElement(type); DumperParaview dumper; dumper.SetMode(TEXT); dumper.SetParallelContext(prank, psize); dumper.SetPoints(mesh.getNodes().values, dim, nb_nodes, "test-scotch-partition"); - dumper.SetConnectivity((int*)mesh.getConnectivity(type).values, + dumper.SetConnectivity((int*) mesh.getConnectivity(type).values, TRIANGLE1, nb_element, C_MODE); double * part = new double[nb_element]; for (unsigned int i = 0; i < nb_element; ++i) part[i] = prank; dumper.AddElemDataField(part, 1, "partitions"); dumper.SetPrefix("paraview/"); dumper.Init(); dumper.Dump(); + + delete part; #endif //AKANTU_USE_IOHELPER akantu::finalize(); return EXIT_SUCCESS; }