list(APPEND ${SRC_VARIABLE} ${SRC_ROOT}/winthreads.cpp)
endif ()
- if (TMPI_CXX_LIB)
- list(APPEND ${SRC_VARIABLE} ${SRC_ROOT}/system_error.cpp)
- endif ()
-
if (TMPI_ENABLED)
list(APPEND ${SRC_VARIABLE}
${SRC_ROOT}/alltoall.cpp ${SRC_ROOT}/p2p_protocol.cpp
+++ /dev/null
-/*
- This source code file is part of thread_mpi.
- Written by Sander Pronk, Erik Lindahl, and possibly others.
-
- Copyright (c) 2009, Sander Pronk, Erik Lindahl.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1) Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2) Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3) Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- If you want to redistribute modifications, please consider that
- scientific software is very special. Version control is crucial -
- bugs must be traceable. We will be happy to consider code for
- inclusion in the official distribution, but derived work should not
- be called official thread_mpi. Details are found in the README & COPYING
- files.
- */
-
-/** \file
- *
- * \brief mutex objects with C++11 API compatibility.
- *
- * This header contains classes mutex and lock_guard, used in C++ mutex
- * implementations safe for exceptions.
- */
-
-#ifndef TMPI_MUTEX_H_
-#define TMPI_MUTEX_H_
-
-#include "visibility.h"
-#include "system_error.h"
-#include "threads.h"
-
-namespace tMPI
-{
-/*! \brief A lock guard class that allows for the simple management of
- mutexes. C++11 compatible.
-
- In C++, mutexes would normally have to be unlocked with explicit
- exception handlers and unlock statements. This class automates that
- by handling the mutex unlock in a destructor. The constructor locks
- the mutex.
-
- Usage example:
- tMPI::mutex mtx;
- void do_count()
- {
- tMPI::lock_guard<tMPI::mutex> lock(mtx);
- count += 1;
- }
- */
-template <class Mutex> class TMPI_EXPORT lock_guard
-{
- public:
- //! Lockable type that this lock operates on.
- typedef Mutex mutex_type;
- /*! \brief The constructor, which locks the mutex.
-
- \param m The exisiting (globally accessible) mutex to lock. */
- explicit lock_guard(mutex_type &m) : m_(m)
- {
- m_.lock();
- }
- //lock_guard(mutex_type &m, adopt_lock_t t);
-
- /*! \brief The destructor, which unlocks the mutex */
- ~lock_guard()
- {
- m_.unlock();
- }
- private:
- // forbid copy constructor & assignment
- lock_guard(const lock_guard &l);
- lock_guard &operator=(const lock_guard &l);
-
- mutex_type &m_;
-};
-
-/*! \brief A basic mutex class with C++11 compatibility. */
-class TMPI_EXPORT mutex
-{
- public:
- //! Type of the native mutex handle.
- typedef tMPI_Thread_mutex_t* native_handle_type;
-
- /*! \brief The constructor.
-
- Throws a tMPI::system_error exception upon failure. */
- mutex()
- {
- int ret = tMPI_Thread_mutex_init(&handle_);
- if (ret)
- {
- throw system_error(ret);
- }
- }
-
- /*! \brief The destructor.*/
- ~mutex()
- {
- tMPI_Thread_mutex_destroy(&handle_);
- }
-
- /*! \brief The lock function.
-
- Throws a tMPI::system_error exception upon failure. */
- void lock()
- {
- int ret = tMPI_Thread_mutex_lock(&handle_);
- if (ret)
- {
- throw system_error(ret);
- }
- }
-
- /*! \brief The try_lock function.
-
- \return true if the lock was locked successfully, false if
- another thread owned it, and implementation-specific if
- already held by this thread. Do not rely on the return code
- if the calling thread could already hold this lock. */
- bool try_lock()
- {
- if (tMPI_Thread_mutex_trylock(&handle_))
- {
- return false;
- }
- return true;
- }
-
- /*! \brief The unlock function.
-
- Throws a tMPI::system_error exception upon failure. */
- void unlock()
- {
- int ret = tMPI_Thread_mutex_unlock(&handle_);
- if (ret)
- {
- throw system_error(ret);
- }
- }
-
- //! Returns the native handle for this mutex.
- native_handle_type native_handle() { return &handle_; }
- private:
- // forbid copy constructor & assignment
- mutex(const mutex &m);
- mutex &operator=(const mutex &m);
-
- tMPI_Thread_mutex_t handle_;
-};
-}
-
-#endif /* TMPI_MUTEX_H_ */
+++ /dev/null
-/*
- This source code file is part of thread_mpi.
- Written by Sander Pronk, Erik Lindahl, and possibly others.
-
- Copyright (c) 2009, Sander Pronk, Erik Lindahl.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1) Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2) Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3) Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- If you want to redistribute modifications, please consider that
- scientific software is very special. Version control is crucial -
- bugs must be traceable. We will be happy to consider code for
- inclusion in the official distribution, but derived work should not
- be called official thread_mpi. Details are found in the README & COPYING
- files.
- */
-
-/** \file
- * \brief A C++11 compatible system_error class for reporting exceptions
- *
- * This header contains class definitions for system_error.
- */
-
-#ifndef TMPI_SYSTEM_ERROR_H_
-#define TMPI_SYSTEM_ERROR_H_
-
-#include <stdexcept>
-
-#include "visibility.h"
-
-namespace tMPI
-{
-/*! \brief Subset of the C++11 system_error class
-
- Only contains the errno-based constructor. */
-class system_error : public std::runtime_error
-{
- public:
- //! Type to represent error codes within this class.
- typedef int error_code;
-
- //system_error(error_code ec, const std::string& what_arg);
- //system_error(error_code ec, const char* what_arg);
- /*! \brief Constuctor that takes an system error number */
- explicit system_error(error_code ec);
-
- /*! \brief Returns the error code */
- const error_code &code() const
- {
- return ec_;
- }
- private:
- error_code ec_;
-};
-}
-
-#endif /* TMPI_SYSTEM_ERROR_H_ */
+++ /dev/null
-/*
- This source code file is part of thread_mpi.
- Written by Sander Pronk, Erik Lindahl, and possibly others.
-
- Copyright (c) 2009, Sander Pronk, Erik Lindahl.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
- 1) Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2) Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3) Neither the name of the copyright holders nor the
- names of its contributors may be used to endorse or promote products
- derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY US ''AS IS'' AND ANY
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- DISCLAIMED. IN NO EVENT SHALL WE BE LIABLE FOR ANY
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
- If you want to redistribute modifications, please consider that
- scientific software is very special. Version control is crucial -
- bugs must be traceable. We will be happy to consider code for
- inclusion in the official distribution, but derived work should not
- be called official thread_mpi. Details are found in the README & COPYING
- files.
- */
-
-#include <cerrno>
-#include <cstring>
-#include <cstdlib>
-#include <stdexcept>
-#include <string>
-#include "thread_mpi/system_error.h"
-
-tMPI::system_error::system_error(error_code ec)
- : runtime_error(std::string(std::strerror(ec))), ec_(ec)
-{
-}
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
- * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <cstdlib>
#include <cstring>
+#include <mutex>
#include <string>
#include <vector>
#include "buildinfo.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
-#include "gromacs/utility/mutex.h"
#include "gromacs/utility/path.h"
#include "gromacs/utility/stringutil.h"
mutable std::string fullBinaryPath_;
mutable std::string installationPrefix_;
mutable bool bSourceLayout_;
- mutable Mutex binaryPathMutex_;
+ mutable std::mutex binaryPathMutex_;
};
CommandLineProgramContext::Impl::Impl() : programName_("GROMACS"), bSourceLayout_(false) {}
const char* CommandLineProgramContext::fullBinaryPath() const
{
- lock_guard<Mutex> lock(impl_->binaryPathMutex_);
+ std::lock_guard<std::mutex> lock(impl_->binaryPathMutex_);
impl_->findBinaryPath();
return impl_->fullBinaryPath_.c_str();
}
InstallationPrefixInfo CommandLineProgramContext::installationPrefix() const
{
- lock_guard<Mutex> lock(impl_->binaryPathMutex_);
+ std::lock_guard<std::mutex> lock(impl_->binaryPathMutex_);
if (impl_->installationPrefix_.empty())
{
impl_->findBinaryPath();
* Returns the full path of the running binary.
*
* \throws std::bad_alloc if out of memory.
- * \throws tMPI::system_error on thread synchronization errors.
*
* Returns argv[0] if there was an error in finding the absolute path.
*/
* Returns the installation prefix (for finding \Gromacs data files).
*
* \throws std::bad_alloc if out of memory.
- * \throws tMPI::system_error on thread synchronization errors.
*
* Returns a hardcoded path set during configuration time if there is
* an error in finding the library data files.
* Copyright (c) 2005,2006,2007,2008,2009 by the GROMACS development team.
* Copyright (c) 2010,2011,2012,2013,2014 by the GROMACS development team.
* Copyright (c) 2015,2016,2017,2018,2019 by the GROMACS development team.
- * Copyright (c) 2020, by the GROMACS development team, led by
+ * Copyright (c) 2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
}
/* Set overallocation to avoid frequent reallocation of arrays */
- set_over_alloc_dd(TRUE);
+ set_over_alloc_dd(true);
dd->atomSets = atomSets;
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2009-2018, The GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#if GMX_FFT_FFTW3
+# include <mutex>
+
# include "gromacs/utility/exceptions.h"
-# include "gromacs/utility/mutex.h"
+
/* none of the fftw3 calls, except execute(), are thread-safe, so
we need to serialize them with this mutex. */
-static gmx::Mutex big_fftw_mutex;
+static std::mutex big_fftw_mutex;
# define FFTW_LOCK \
try \
{ \
*
* Copyright (c) 1991-2003 David van der Spoel, Erik Lindahl, University of Groningen.
* Copyright (c) 2013,2014,2015,2017,2018 by the GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <cerrno>
#include <cstdlib>
+#include <mutex>
+
#include <fftw3.h>
#include "gromacs/fft/fft.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/mutex.h"
#if GMX_DOUBLE
# define FFTWPREFIX(name) fftw_##name
/* none of the fftw3 calls, except execute(), are thread-safe, so
we need to serialize them with this mutex. */
-static gmx::Mutex big_fftw_mutex;
+static std::mutex big_fftw_mutex;
#define FFTW_LOCK \
try \
{ \
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <cstdio>
#include <cstring>
+#include <mutex>
#include <vector>
#if HAVE_IO_H
#include "gromacs/fileio/md5.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
-#include "gromacs/utility/mutex.h"
#include "gromacs/utility/smalloc.h"
#include "gmxfio_impl.h"
opening and closing of files, or during global operations like
iterating along all open files. All these cases should be rare
during the simulation. */
-static gmx::Mutex open_file_mutex;
+static std::mutex open_file_mutex;
-using Lock = gmx::lock_guard<gmx::Mutex>;
+using Lock = std::lock_guard<std::mutex>;
/******************************************************************
*
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2018,2019,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "timecontrol.h"
-#include "thread_mpi/threads.h"
+#include <mutex>
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/fatalerror.h"
static t_timecontrol timecontrol[TNR] = { { 0, FALSE }, { 0, FALSE }, { 0, FALSE } };
-static tMPI_Thread_mutex_t tc_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
+static std::mutex g_timeControlMutex;
gmx_bool bTimeSet(int tcontrol)
{
gmx_bool ret;
- tMPI_Thread_mutex_lock(&tc_mutex);
+ const std::lock_guard<std::mutex> lock(g_timeControlMutex);
range_check(tcontrol, 0, TNR);
ret = timecontrol[tcontrol].bSet;
- tMPI_Thread_mutex_unlock(&tc_mutex);
return ret;
}
{
real ret;
- tMPI_Thread_mutex_lock(&tc_mutex);
+ const std::lock_guard<std::mutex> lock(g_timeControlMutex);
range_check(tcontrol, 0, TNR);
ret = timecontrol[tcontrol].t;
- tMPI_Thread_mutex_unlock(&tc_mutex);
return ret;
}
void setTimeValue(int tcontrol, real value)
{
- tMPI_Thread_mutex_lock(&tc_mutex);
+ const std::lock_guard<std::mutex> lock(g_timeControlMutex);
range_check(tcontrol, 0, TNR);
timecontrol[tcontrol].t = value;
timecontrol[tcontrol].bSet = TRUE;
- tMPI_Thread_mutex_unlock(&tc_mutex);
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "config.h"
+#include <mutex>
+
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/exceptions.h"
-#include "gromacs/utility/mutex.h"
#include "gromacs/utility/stringutil.h"
#if GMX_GPU_OPENCL
* initialize it more than once. */
//! @{
bool g_clfftInitialized = false;
-gmx::Mutex g_clfftMutex;
+std::mutex g_clfftMutex;
//! @}
#endif
ClfftInitializer::ClfftInitializer()
{
#if GMX_GPU_OPENCL
- gmx::lock_guard<gmx::Mutex> guard(g_clfftMutex);
+ std::lock_guard<std::mutex> guard(g_clfftMutex);
clfftSetupData fftSetup;
int initErrorCode = clfftInitSetupData(&fftSetup);
if (initErrorCode != 0)
ClfftInitializer::~ClfftInitializer()
{
#if GMX_GPU_OPENCL
- gmx::lock_guard<gmx::Mutex> guard(g_clfftMutex);
+ std::lock_guard<std::mutex> guard(g_clfftMutex);
if (g_clfftInitialized)
{
clfftTeardown();
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
- * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
# include <limits>
#endif
-#include "thread_mpi/atomic.h"
-
#include "gromacs/gpu_utils/device_context.h"
#include "gromacs/gpu_utils/gputraits_ocl.h"
#include "gromacs/gpu_utils/oclutils.h"
#include <algorithm>
#include <memory>
+#include <mutex>
#include "gromacs/commandline/filenm.h"
#include "gromacs/domdec/domdec_struct.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
#include "gromacs/utility/gmxassert.h"
-#include "gromacs/utility/mutex.h"
#include "gromacs/utility/pleasecite.h"
#include "gromacs/utility/real.h"
#include "gromacs/utility/smalloc.h"
* We could use a different, local mutex for each pull object, but the overhead
* is extremely small here and registration is only done during initialization.
*/
-static gmx::Mutex registrationMutex;
+static std::mutex registrationMutex;
-using Lock = gmx::lock_guard<gmx::Mutex>;
+using Lock = std::lock_guard<std::mutex>;
void register_external_pull_potential(struct pull_t* pull, int coord_index, const char* provider)
{
#include <cstring>
#include <algorithm>
+#include <mutex>
#include <vector>
#include "gromacs/math/functions.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/listoflists.h"
-#include "gromacs/utility/mutex.h"
#include "gromacs/utility/stringutil.h"
#include "position.h"
//! Data structure to hold the grid cell contents.
CellList cells_;
- Mutex createPairSearchMutex_;
+ std::mutex createPairSearchMutex_;
PairSearchList pairSearchList_;
friend class AnalysisNeighborhoodPairSearchImpl;
AnalysisNeighborhoodSearchImpl::PairSearchImplPointer AnalysisNeighborhoodSearchImpl::getPairSearch()
{
- lock_guard<Mutex> lock(createPairSearchMutex_);
+ std::lock_guard<std::mutex> lock(createPairSearchMutex_);
// TODO: Consider whether this needs to/can be faster, e.g., by keeping a
// separate pool of unused search objects.
PairSearchList::const_iterator i;
SearchImplPointer getSearch();
- Mutex createSearchMutex_;
+ std::mutex createSearchMutex_;
SearchList searchList_;
real cutoff_;
const ListOfLists<int>* excls_;
AnalysisNeighborhood::Impl::SearchImplPointer AnalysisNeighborhood::Impl::getSearch()
{
- lock_guard<Mutex> lock(createSearchMutex_);
+ std::lock_guard<std::mutex> lock(createSearchMutex_);
// TODO: Consider whether this needs to/can be faster, e.g., by keeping a
// separate pool of unused search objects.
SearchList::const_iterator i;
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2011-2018, The GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <stdexcept>
#include <typeinfo>
-#include "thread_mpi/system_error.h"
-
#include "gromacs/utility/basenetwork.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/gmxassert.h"
{
title = getErrorCodeString(gmxEx->errorCode());
}
- else if (dynamic_cast<const tMPI::system_error*>(&ex) != nullptr)
- {
- title = "System error in thread synchronization";
- }
else if (dynamic_cast<const std::bad_alloc*>(&ex) != nullptr)
{
title = "Memory allocation failed";
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017, The GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <cstring>
#include <exception>
+#include <mutex>
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/baseversion.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/futil.h"
-#include "gromacs/utility/mutex.h"
#include "gromacs/utility/programcontext.h"
#include "gromacs/utility/stringutil.h"
gmx_bool gmx_debug_at = FALSE;
static FILE* log_file = nullptr;
-static gmx::Mutex error_mutex;
+static std::mutex error_mutex;
-using Lock = gmx::lock_guard<gmx::Mutex>;
+using Lock = std::lock_guard<std::mutex>;
void gmx_init_debug(const int dbglevel, const char* dbgfile)
{
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017, The GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <cstdlib>
#include <cstring>
+#include <mutex>
#include <tuple>
#include <fcntl.h>
#include "gromacs/utility/dir_separator.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/fatalerror.h"
-#include "gromacs/utility/mutex.h"
#include "gromacs/utility/path.h"
#include "gromacs/utility/programcontext.h"
#include "gromacs/utility/smalloc.h"
/* this linked list is an intrinsically globally shared object, so we have
to protect it with mutexes */
-static gmx::Mutex pstack_mutex;
+static std::mutex pstack_mutex;
-using Lock = gmx::lock_guard<gmx::Mutex>;
+using Lock = std::lock_guard<std::mutex>;
namespace gmx
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2016,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2016,2017,2018,2019,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include "keyvaluetreeserializer.h"
+#include <mutex>
+
#include "gromacs/utility/iserializer.h"
#include "gromacs/utility/keyvaluetree.h"
#include "gromacs/utility/keyvaluetreebuilder.h"
-#include "gromacs/utility/mutex.h"
namespace gmx
{
DeserializerFunction deserialize;
};
- static Mutex s_initMutex;
+ static std::mutex s_initMutex;
static std::map<std::type_index, Serializer> s_serializers;
static std::map<unsigned char, DeserializerFunction> s_deserializers;
};
-Mutex ValueSerializer::s_initMutex;
+std::mutex ValueSerializer::s_initMutex;
std::map<std::type_index, ValueSerializer::Serializer> ValueSerializer::s_serializers;
std::map<unsigned char, ValueSerializer::DeserializerFunction> ValueSerializer::s_deserializers;
// static
void ValueSerializer::initSerializers()
{
- lock_guard<Mutex> lock(s_initMutex);
+ std::lock_guard<std::mutex> lock(s_initMutex);
if (!s_serializers.empty())
{
return;
+++ /dev/null
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 2015, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-/*! \libinternal \file
- * \brief
- * Declares C++11-style basic threading primitives
- * (gmx::Mutex, gmx::lock_guard).
- *
- * For now, the implementation is imported from thread-MPI.
- *
- * \author Teemu Murtola <teemu.murtola@gmail.com>
- * \inlibraryapi
- * \ingroup module_utility
- */
-#ifndef GMX_THREADING_MUTEX_H
-#define GMX_THREADING_MUTEX_H
-
-#include "thread_mpi/mutex.h"
-
-namespace gmx
-{
-
-//! \cond libapi
-/*! \libinternal \brief
- * C++11-compatible basic mutex.
- */
-typedef tMPI::mutex Mutex;
-//! \endcond
-using tMPI::lock_guard;
-
-} // namespace gmx
-
-#endif
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
* Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
#include <cstdio>
#include <cstdlib>
+#include <mutex>
+
#ifdef WITH_DMALLOC
# include <dmalloc.h>
#endif
#include <cstring>
-#include "thread_mpi/threads.h"
-
#include "gromacs/utility/alignedallocator.h"
#include "gromacs/utility/dir_separator.h"
#include "gromacs/utility/fatalerror.h"
# include "gromacs/utility/gmxmpi.h"
#endif
-static gmx_bool g_bOverAllocDD = FALSE;
-static tMPI_Thread_mutex_t g_over_alloc_mutex = TMPI_THREAD_MUTEX_INITIALIZER;
+static bool g_bOverAllocDD = false;
+static std::mutex g_overAllocMutex;
void* save_malloc(const char* name, const char* file, int line, size_t size)
{
gmx::AlignedAllocationPolicy::free(ptr);
}
-void set_over_alloc_dd(gmx_bool set)
+void set_over_alloc_dd(bool set)
{
- tMPI_Thread_mutex_lock(&g_over_alloc_mutex);
+ std::lock_guard<std::mutex> lock(g_overAllocMutex);
/* we just make sure that we don't set this at the same time.
We don't worry too much about reading this rarely-set variable */
g_bOverAllocDD = set;
- tMPI_Thread_mutex_unlock(&g_over_alloc_mutex);
}
int over_alloc_dd(int n)
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2018,2019,2020, by the GROMACS development team.
+ * Copyright (c) 2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* This is mdrun-specific, so it might be better to put this and
* over_alloc_dd() much higher up.
*/
-void set_over_alloc_dd(gmx_bool set);
+void set_over_alloc_dd(bool set);
/*! \brief
* Returns new allocation count for domain decomposition allocations.
# This file is part of the GROMACS molecular simulation package.
#
# Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
-# Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+# Copyright (c) 2017,2018,2019,2020,2021, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
listoflists.cpp
logger.cpp
mdmodulenotification-impl.cpp
- mutex.cpp
path.cpp
physicalnodecommunicator.cpp
range.cpp
+++ /dev/null
-/*
- * This file is part of the GROMACS molecular simulation package.
- *
- * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
- * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
- * and including many others, as listed in the AUTHORS file in the
- * top-level source directory and at http://www.gromacs.org.
- *
- * GROMACS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- *
- * GROMACS is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with GROMACS; if not, see
- * http://www.gnu.org/licenses, or write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * If you want to redistribute modifications to GROMACS, please
- * consider that scientific software is very special. Version
- * control is crucial - bugs must be traceable. We will be happy to
- * consider code for inclusion in the official distribution, but
- * derived work must not be called official GROMACS. Details are found
- * in the README & COPYING files - if they are missing, get the
- * official version at http://www.gromacs.org.
- *
- * To help us fund GROMACS development, we humbly ask that you cite
- * the research papers on the package. Check out http://www.gromacs.org.
- */
-/*! \internal \file
- * \brief Tests for gmx::Mutex
- *
- * These tests ensure that basic mutual-exclusion properties hold.
- * Note that no testing can prove there isn't a bug, but if one
- * exists, then these tests might expose one.
- *
- * In particular, try_lock can be implemented differently on different
- * platforms, or with different default mutex types, so we should
- * check that the behaviour continues to conform with the thread-MPI
- * documentation.
- *
- * \author Mark Abraham <mark.j.abraham@gmail.com>
- * \ingroup module_utility
- */
-
-#include "gmxpre.h"
-
-#include "gromacs/utility/mutex.h"
-
-#include "config.h"
-
-#include <future>
-
-#include <gtest/gtest.h>
-
-
-namespace gmx
-{
-namespace test
-{
-namespace
-{
-
-//! Convenience definition.
-using Lock = gmx::lock_guard<Mutex>;
-
-TEST(MutexBasicTest, CanBeMade)
-{
- Mutex m;
-}
-
-TEST(MutexBasicTest, CanBeLocked)
-{
- Mutex m;
- ASSERT_NO_THROW(m.lock());
- m.unlock();
-}
-
-TEST(MutexBasicTest, CanBeTryLocked)
-{
- Mutex m;
- ASSERT_TRUE(m.try_lock());
- m.unlock();
-}
-
-TEST(MutexBasicTest, CanBeUsedInLockGuard)
-{
- Mutex m;
- Lock g(m);
-}
-
-//! A shared value for a mutex to protect
-int g_sharedValue;
-//! A mutex to protect a shared value
-Mutex g_sharedValueMutex;
-
-//! Function type for asynchronous tasks.
-using TaskType = std::function<int(void)>;
-
-//! A task that just does work.
-int updateSharedValue()
-{
- return ++g_sharedValue;
-}
-
-//! A task that does work after it gets the mutex.
-int updateSharedValueWithLock()
-{
- Lock guard(g_sharedValueMutex);
- return updateSharedValue();
-}
-
-//! A task that does work only if it can get the mutex immediately.
-int updateSharedValueWithTryLock()
-{
- // Special return value to signal when work was not done because
- // the lock was not acquired.
- int result = -1;
- if (g_sharedValueMutex.try_lock())
- {
- result = updateSharedValue();
- g_sharedValueMutex.unlock();
- }
- return result;
-}
-
-/*! \brief Parameterized test fixture.
- *
- * Checks that different launch policies work. In further tests of
- * mutual exclusion, we need to specify std::thread::async, to require
- * that a thread actually launched. The default policy permits the
- * std:: implementation to avoid launching a thread, and at least the
- * behaviour of thread-MPI try_lock also varies with the threading
- * implementation underlying it. */
-class DifferentTasksTest : public ::testing::TestWithParam<TaskType>
-{
-public:
- DifferentTasksTest() { g_sharedValue = 0; }
- //! Check the results
- void checkResults()
- {
- int result = 0;
- EXPECT_NO_THROW(result = futureResult_.get()) << "Future should not contain an exception";
- EXPECT_EQ(1, result) << "Task should have run";
- EXPECT_EQ(1, g_sharedValue) << "Shared value should be updated";
- }
- //! Contains the result the task returns.
- std::future<int> futureResult_;
-};
-
-TEST_P(DifferentTasksTest, StdAsyncWorksWithDefaultPolicy)
-{
- auto task = GetParam();
- EXPECT_NO_THROW(futureResult_ = std::async(task)) << "Async should succeed";
- checkResults();
-}
-
-TEST_P(DifferentTasksTest, StdAsyncWorksWithAsyncLaunchPolicy)
-{
- auto task = GetParam();
- EXPECT_NO_THROW(futureResult_ = std::async(std::launch::async, task)) << "Async should succeed";
- checkResults();
-}
-
-TEST_P(DifferentTasksTest, StdAsyncWorksWithDeferredLaunchPolicy)
-{
- auto task = GetParam();
- EXPECT_NO_THROW(futureResult_ = std::async(std::launch::deferred, task))
- << "Async should succeed";
- checkResults();
-}
-
-// Test that the different launch policies work with the different tasks
-INSTANTIATE_TEST_CASE_P(WithAndWithoutMutex,
- DifferentTasksTest,
- ::testing::Values(updateSharedValue,
- updateSharedValueWithLock,
- updateSharedValueWithTryLock));
-
-TEST(MutexTaskTest, MutualExclusionWorksWithLock)
-{
- g_sharedValue = 0;
- std::future<int> result;
- {
- // Hold the mutex, launch a lock attempt on another
- // thread, check that the shared value isn't changed, then
- // release the mutex by leaving the scope, after which the
- // other thread's lock can get the mutex.
- Lock guard(g_sharedValueMutex);
- result = std::async(std::launch::async, updateSharedValueWithLock);
- EXPECT_EQ(0, g_sharedValue) << "Task should not have run yet";
- }
- EXPECT_EQ(1, result.get()) << "Task should have run";
- EXPECT_EQ(1, g_sharedValue) << "Shared value should be updated";
-}
-
-TEST(MutexTaskTest, MutualExclusionWorksWithTryLockOnOtherThread)
-{
- g_sharedValue = 0;
- {
- // Hold the mutex, launch a try_lock attempt on another
- // thread, check that the shared value isn't changed, then
- // make sure the try_lock attempt has returned, double check
- // that the shared value isn't changed, and release the mutex
- // by leaving the scope.
- Lock guard(g_sharedValueMutex);
- auto result = std::async(std::launch::async, updateSharedValueWithTryLock);
- EXPECT_EQ(0, g_sharedValue) << "Data race detected";
- EXPECT_EQ(-1, result.get()) << "The try_lock should fail";
- EXPECT_EQ(0, g_sharedValue) << "Task should not have run";
- }
- EXPECT_EQ(0, g_sharedValue) << "Mutex release can't affect the protected value";
-}
-
-TEST(MutexTaskTest, MutualExclusionWorksWithTryLockOnSameThread)
-{
- g_sharedValue = 0;
- int finalSharedValue = GMX_NATIVE_WINDOWS ? 1 : 0;
- {
- // Hold the mutex and launch a try_lock attempt on this
- // thread. Behaviour then varies with the implementation
- // underlying thread-MPI.
- Lock guard(g_sharedValueMutex);
- int result = updateSharedValueWithTryLock();
- if (GMX_NATIVE_WINDOWS)
- {
- EXPECT_EQ(1, result) << "The try_lock should succeed";
- EXPECT_EQ(finalSharedValue, g_sharedValue) << "Task should have run";
- }
- else
- {
- EXPECT_EQ(-1, result) << "The try_lock should fail";
- EXPECT_EQ(finalSharedValue, g_sharedValue) << "Task should not have run";
- }
- }
- EXPECT_EQ(finalSharedValue, g_sharedValue) << "Mutex release can't affect the protected value";
-}
-
-} // namespace
-} // namespace test
-} // namespace gmx
* This file is part of the GROMACS molecular simulation package.
*
* Copyright (c) 2012,2013,2014,2015,2018 by the GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* \param[in] name Name of the options provider (for ordering).
* \param[in] provider The provider to register.
* \throws std::bad_alloc if out of memory.
- * \throws tMPI::system_error on mutex failures.
*
* Typically not used directly in test code, but through the
* #GMX_TEST_OPTIONS macro.
#include "testutils/testoptions.h"
#include <list>
+#include <mutex>
#include <memory>
#include "gromacs/utility/classhelpers.h"
-#include "gromacs/utility/mutex.h"
namespace gmx
{
//! Adds a provider into the registry.
void add(const char* /*name*/, TestOptionsProvider* provider)
{
- lock_guard<Mutex> lock(listMutex_);
+ std::lock_guard<std::mutex> lock(listMutex_);
providerList_.push_back(provider);
}
typedef std::list<TestOptionsProvider*> ProviderList;
- Mutex listMutex_;
+ std::mutex listMutex_;
ProviderList providerList_;
GMX_DISALLOW_COPY_AND_ASSIGN(TestOptionsRegistry);
{
// TODO: Have some deterministic order for the options; now it depends on
// the order in which the global initializers are run.
- lock_guard<Mutex> lock(listMutex_);
+ std::lock_guard<std::mutex> lock(listMutex_);
ProviderList::const_iterator i;
for (i = providerList_.begin(); i != providerList_.end(); ++i)
{