1
1
Add a framework to support different types of threading models including
user space thread packages such as Qthreads and argobot:

https://github.com/pmodels/argobots

https://github.com/Qthreads/qthreads

The default threading model is pthreads.  Alternate thread models are
specificed at configure time using the --with-threads=X option.

The framework is static.  The theading model to use is selected at
Open MPI configure/build time.

mca/threads: implement Argobots threading layer

config: fix thread configury

- Add double quotations
- Change Argobot to Argobots
config: implement Argobots check

If the poll time is too long, MPI hangs.

This quick fix just sets it to 0, but it is not good for the
Pthreads version. Need to find a good way to abstract it.

Note that even 1 (= 1 millisecond) causes disastrous performance
degradation.

rework threads MCA framework configury

It now works more like the ompi/mca/rte configury,
modulo some edge items that are special for threading package
linking, etc.

qthreads module
some argobots cleanup

Signed-off-by: Noah Evans <noah.evans@gmail.com>
Signed-off-by: Shintaro Iwasaki <siwasaki@anl.gov>
Signed-off-by: Howard Pritchard <howardp@lanl.gov>
Этот коммит содержится в:
Noah Evans 2019-02-04 20:20:37 -07:00 коммит произвёл Howard Pritchard
родитель b3f0bc5490
Коммит ee3517427e
141 изменённых файлов: 3476 добавлений и 813 удалений

Просмотреть файл

@ -1,112 +0,0 @@
dnl
dnl Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
dnl University Research and Technology
dnl Corporation. All rights reserved.
dnl Copyright (c) 2004-2005 The University of Tennessee and The University
dnl of Tennessee Research Foundation. All rights
dnl reserved.
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
dnl University of Stuttgart. All rights reserved.
dnl Copyright (c) 2004-2005 The Regents of the University of California.
dnl All rights reserved.
dnl Copyright (c) 2008-2013 Cisco Systems, Inc. All rights reserved.
dnl $COPYRIGHT$
dnl
dnl Additional copyrights may follow
dnl
dnl $HEADER$
dnl
AC_DEFUN([OPAL_CHECK_PTHREAD_PIDS],[
#
# Arguments: none
#
# Dependencies: None
#
# Sets:
# OPAL_THREADS_HAVE_DIFFERENT_PIDS (variable)
#
# Test for Linux-like threads in the system. OPAL no longer supports
# systems with different PIDs for threads in the same process, so error
# out if we detect that case.
#
AC_MSG_CHECKING([if threads have different pids (pthreads on linux)])
OPAL_VAR_SCOPE_PUSH([CFLAGS_save CPPFLAGS_save LDFLAGS_save LIBS_save MSG])
CFLAGS_save="$CFLAGS"
CFLAGS="$CFLAGS $THREAD_CFLAGS"
CPPFLAGS_save="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $THREAD_CPPFLAGS"
LDFLAGS_save="$LDFLAGS"
LDFLAGS="$LDFLAGS $THREAD_LDFLAGS"
LIBS_save="$LIBS"
LIBS="$LIBS $THREAD_LIBS"
AC_RUN_IFELSE([AC_LANG_SOURCE([#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
void *checkpid(void *arg);
int main() {
pthread_t thr;
int pid, *retval;
pid = getpid();
pthread_create(&thr, NULL, checkpid, &pid);
pthread_join(thr, (void **) &retval);
exit(*retval);
}
static int ret;
void *checkpid(void *arg) {
int ppid = *((int *) arg);
if (ppid == getpid())
ret = 0;
else
ret = 1;
pthread_exit((void *) &ret);
}])],
[MSG=no OPAL_THREADS_HAVE_DIFFERENT_PIDS=0],
[MSG=yes OPAL_THREADS_HAVE_DIFFERENT_PIDS=1],
[
# If we're cross compiling, we can't do another AC_* function here because
# it we haven't displayed the result from the last one yet. So defer
# another test until below.
OPAL_THREADS_HAVE_DIFFERENT_PIDS=
MSG="cross compiling (need another test)"])
CFLAGS="$CFLAGS_save"
CPPFLAGS="$CPPFLAGS_save"
LDFLAGS="$LDFLAGS_save"
LIBS="$LIBS_save"
AC_MSG_RESULT([$MSG])
AS_IF([test "x$OPAL_THREADS_HAVE_DIFFERENT_PIDS" = "x"],
[ # If we are cross-compiling, look for the symbol
# __linuxthreads_create_event, which seems to only exist in the
# Linux Threads-based pthreads implementation (i.e., the one
# that has different PIDs for each thread). We *could* switch
# on $host here and only test *linux* hosts, but this test is
# pretty unique, so why bother? Note that AC_CHECK_FUNC works
# properly in cross-compiling environments in recent-enough
# versions of Autoconf (which is one of the reasons we mandate
# recent versions in autogen!).
AC_CHECK_FUNC([__linuxthreads_create_event],
[OPAL_THREADS_HAVE_DIFFERENT_PIDS=1])])
AS_IF([test "$OPAL_THREADS_HAVE_DIFFERENT_PIDS" = "1"],
[AC_MSG_WARN([This version of Open MPI only supports environments where])
AC_MSG_WARN([threads have the same PID. Please use an older version of])
AC_MSG_WARN([Open MPI if you need support on systems with different])
AC_MSG_WARN([PIDs for threads in the same process. Open MPI 1.4.x])
AC_MSG_WARN([supports such systems, as does at least some versions the])
AC_MSG_WARN([Open MPI 1.5.x series.])
AC_MSG_ERROR([Cannot continue])
])
#
# if pthreads is not available, then the system does not have an insane threads
# model
#
OPAL_VAR_SCOPE_POP])dnl

Просмотреть файл

@ -1,69 +0,0 @@
dnl
dnl Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
dnl University Research and Technology
dnl Corporation. All rights reserved.
dnl Copyright (c) 2004-2005 The University of Tennessee and The University
dnl of Tennessee Research Foundation. All rights
dnl reserved.
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
dnl University of Stuttgart. All rights reserved.
dnl Copyright (c) 2004-2005 The Regents of the University of California.
dnl All rights reserved.
dnl Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
dnl Copyright (c) 2009-2011 Oak Ridge National Labs. All rights reserved.
dnl Copyright (c) 2014 Intel, Inc. All rights reserved
dnl Copyright (c) 2015 Research Organization for Information Science
dnl and Technology (RIST). All rights reserved.
dnl $COPYRIGHT$
dnl
dnl Additional copyrights may follow
dnl
dnl $HEADER$
dnl
AC_DEFUN([OPAL_CONFIG_THREADS],[
#
# Arguments: none
#
# Dependencies: None
#
# Modifies:
# none - see called tests
#
# configure threads
#
#
# Check we have POSIX threads
#
OPAL_CONFIG_POSIX_THREADS(HAVE_POSIX_THREADS=1, HAVE_POSIX_THREADS=0)
AC_MSG_CHECKING([for working POSIX threads package])
if test "$HAVE_POSIX_THREADS" = "1" ; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
export HAVE_POSIX_THREADS
#
# Ask what threading we want (allow posix right now)
#
if test "$HAVE_POSIX_THREADS" = "0"; then
AC_MSG_WARN(["*** POSIX threads are not"])
AC_MSG_WARN(["*** available on your system "])
AC_MSG_ERROR(["*** Can not continue"])
fi
THREAD_CFLAGS="$PTHREAD_CFLAGS"
THREAD_FCFLAGS="$PTHREAD_FCFLAGS"
THREAD_CXXFLAGS="$PTHREAD_CXXFLAGS"
THREAD_CPPFLAGS="$PTHREAD_CPPFLAGS"
THREAD_CXXCPPFLAGS="$PTHREAD_CXXCPPFLAGS"
THREAD_LDFLAGS="$PTHREAD_LDFLAGS"
THREAD_LIBS="$PTHREAD_LIBS"
OPAL_CHECK_PTHREAD_PIDS
])dnl

Просмотреть файл

@ -26,6 +26,8 @@
# Copyright (c) 2018 Amazon.com, Inc. or its affiliates.
# All Rights reserved.
# Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
# Copyright (c) 2019 Triad National Security, LLC. All rights
# reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
@ -945,22 +947,6 @@ OPAL_CHECK_BROKEN_QSORT
# all: type of getsockopt optlen
# all: type of recvfrom optlen
#
# Check out what thread support we have
#
OPAL_CONFIG_THREADS
CFLAGS="$CFLAGS $THREAD_CFLAGS"
CPPFLAGS="$CPPFLAGS $THREAD_CPPFLAGS"
LDFLAGS="$LDFLAGS $THREAD_LDFLAGS"
LIBS="$LIBS $THREAD_LIBS"
OPAL_WRAPPER_FLAGS_ADD([CFLAGS], [$THREAD_CFLAGS])
OPAL_WRAPPER_FLAGS_ADD([CXXFLAGS], [$THREAD_CXXFLAGS])
OPAL_WRAPPER_FLAGS_ADD([FCFLAGS], [$THREAD_FCFLAGS])
OPAL_WRAPPER_FLAGS_ADD([LDFLAGS], [$THREAD_LDFLAGS])
# no need to update WRAPPER_EXTRA_LIBS - we'll get it from LT later
#
# What is the local equivalent of "ln -s"
#
@ -1113,6 +1099,14 @@ AC_MSG_RESULT([$opal_subdir_args])
OPAL_MCA
#
# Now that we know how to support threads with wrappers, update
#
OPAL_WRAPPER_FLAGS_ADD([CFLAGS], [$THREAD_CFLAGS])
OPAL_WRAPPER_FLAGS_ADD([CXXFLAGS], [$THREAD_CXXFLAGS])
OPAL_WRAPPER_FLAGS_ADD([FCFLAGS], [$THREAD_FCFLAGS])
OPAL_WRAPPER_FLAGS_ADD([LDFLAGS], [$THREAD_LDFLAGS])
m4_ifdef([project_ompi], [OMPI_REQUIRE_ENDPOINT_TAG_FINI])
# Last minute disable of OpenSHMEM if we didn't find any oshmem SPMLs

Просмотреть файл

@ -232,7 +232,7 @@
#include "ompi_config.h"
#include "opal/class/opal_bitmap.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/sys/atomic.h"
#include "ompi/attribute/attribute.h"

Просмотреть файл

@ -41,7 +41,7 @@
#include "opal/util/string_copy.h"
#include "ompi/proc/proc.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/util/bit_ops.h"
#include "opal/util/output.h"
#include "ompi/mca/topo/topo.h"

Просмотреть файл

@ -36,7 +36,7 @@
#include "opal/class/opal_hash_table.h"
#include "opal/util/info_subscriber.h"
#include "ompi/errhandler/errhandler.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "ompi/communicator/comm_request.h"
#include "mpi.h"

Просмотреть файл

@ -30,7 +30,7 @@
#include "mpi.h"
#include "opal/class/opal_list.h"
#include "ompi/errhandler/errhandler.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/util/info_subscriber.h"
#include "ompi/mca/io/io.h"

Просмотреть файл

@ -32,7 +32,7 @@
#include "opal/util/info.h"
#include "opal/class/opal_list.h"
#include "opal/class/opal_pointer_array.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/mca/base/mca_base_var_enum.h"

Просмотреть файл

@ -58,7 +58,7 @@ writing 4x4 matrix to monitoring_avg.mat
#define OMPI_COMPILING_FORTRAN_WRAPPERS 1
#endif
#include "opal/threads/thread_usage.h"
#include "opal/mca/threads/thread_usage.h"
#include "ompi/include/mpi.h"
#include "ompi/mpi/fortran/base/constants.h"

Просмотреть файл

@ -29,7 +29,7 @@
#include "mpi.h"
#include "opal/class/opal_list.h"
#include "ompi/errhandler/errhandler.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "ompi/file/file.h"
#include "ompi/mca/io/io.h"
#include "ompi/mca/fs/fs.h"

Просмотреть файл

@ -29,7 +29,7 @@
#include "mpi.h"
#include "opal/class/opal_list.h"
#include "ompi/errhandler/errhandler.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "ompi/file/file.h"
#include "ompi/mca/io/io.h"
#include "ompi/mca/fs/fs.h"

Просмотреть файл

@ -28,7 +28,7 @@
#include "mpi.h"
#include "opal/class/opal_list.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/mca/base/base.h"
#include "ompi/mca/io/io.h"
#include "ompi/mca/fs/base/base.h"

Просмотреть файл

@ -20,7 +20,7 @@
#include "ompi_config.h"
#include "mpi.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "ompi/mca/io/io.h"
#include "io_ompio.h"

Просмотреть файл

@ -24,7 +24,7 @@
#define MCA_IO_ROMIO321_H
#include "ompi_config.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "ompi/request/request.h"
#include "ompi/file/file.h"
#include "ompi/mca/io/io.h"

Просмотреть файл

@ -27,7 +27,7 @@
#include "mpi.h"
#include "opal/class/opal_list.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/mca/base/base.h"
#include "ompi/mca/io/io.h"
#include "io_romio321.h"

Просмотреть файл

@ -30,7 +30,7 @@
#include "opal/class/opal_list.h"
#include "opal/class/opal_free_list.h"
#include "opal/class/opal_hash_table.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/threads.h"
#include "opal/util/output.h"
#include "ompi/win/win.h"

Просмотреть файл

@ -33,7 +33,7 @@
#include "mpi.h"
#include "opal/runtime/opal_progress.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "ompi/communicator/communicator.h"
#include "ompi/mca/osc/base/base.h"

Просмотреть файл

@ -31,7 +31,7 @@
#include "mpi.h"
#include "opal/runtime/opal_progress.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "ompi/communicator/communicator.h"
#include "ompi/mca/osc/base/base.h"
#include "opal/include/opal_stdint.h"

Просмотреть файл

@ -14,7 +14,7 @@
#include "ompi_config.h"
#include "opal/class/opal_free_list.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/threads.h"
enum ompi_osc_pt2pt_sync_type_t {
/** default value */

Просмотреть файл

@ -27,7 +27,7 @@
#include "ompi_config.h"
#include "opal/class/opal_free_list.h"
#include "opal/class/opal_hash_table.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/threads.h"
#include "opal/util/output.h"
#include "opal/mca/shmem/shmem.h"

Просмотреть файл

@ -31,7 +31,7 @@
#include "osc_rdma_active_target.h"
#include "mpi.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "ompi/communicator/communicator.h"
#include "ompi/mca/osc/base/base.h"

Просмотреть файл

@ -42,7 +42,7 @@
#include "osc_rdma_dynamic.h"
#include "osc_rdma_accumulate.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/util/arch.h"
#include "opal/util/argv.h"
#include "opal/util/printf.h"

Просмотреть файл

@ -14,7 +14,7 @@
#include "osc_rdma_types.h"
#include "opal/class/opal_object.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/threads.h"
/**
* @brief synchronization types

Просмотреть файл

@ -24,8 +24,8 @@
*/
#include "ompi_config.h"
#include "opal/threads/mutex.h"
#include "opal/threads/condition.h"
#include "opal/mca/threads/mutex.h"
#include "opal/mca/threads/condition.h"
#include "ompi/datatype/ompi_datatype.h"
#include "opal/mca/allocator/base/base.h"
#include "opal/mca/allocator/allocator.h"

Просмотреть файл

@ -26,7 +26,7 @@
#ifndef MCA_PML_OB1_COMM_H
#define MCA_PML_OB1_COMM_H
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/class/opal_list.h"
#include "ompi/proc/proc.h"
#include "ompi/communicator/communicator.h"

Просмотреть файл

@ -33,7 +33,7 @@
#include "ompi_config.h"
#include "opal/class/opal_list.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/prefetch.h"
#include "ompi/constants.h"

Просмотреть файл

@ -23,7 +23,7 @@
#include <string.h>
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/util/string_copy.h"
#include "ompi/mpi/c/bindings.h"

Просмотреть файл

@ -25,7 +25,7 @@
#include "ompi/communicator/communicator.h"
#include "ompi/errhandler/errhandler.h"
#include "ompi/runtime/mpiruntime.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/threads.h"
#if OMPI_BUILD_MPI_PROFILING
#if OPAL_HAVE_WEAK_SYMBOLS

Просмотреть файл

@ -32,7 +32,7 @@
#include "ompi/constants.h"
#include "opal/datatype/opal_convertor.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/dss/dss.h"
#include "opal/util/arch.h"
#include "opal/util/show_help.h"

Просмотреть файл

@ -35,8 +35,8 @@
#include "mpi.h"
#include "opal/class/opal_free_list.h"
#include "opal/class/opal_pointer_array.h"
#include "opal/threads/condition.h"
#include "opal/threads/wait_sync.h"
#include "opal/mca/threads/condition.h"
#include "opal/mca/threads/wait_sync.h"
#include "ompi/constants.h"
BEGIN_C_DECLS

Просмотреть файл

@ -36,7 +36,7 @@
#include "opal/class/opal_list.h"
#include "opal/class/opal_hash_table.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
BEGIN_C_DECLS

Просмотреть файл

@ -46,7 +46,7 @@
#include "opal/mca/base/base.h"
#include "opal/mca/hwloc/base/base.h"
#include "opal/runtime/opal_progress.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/threads.h"
#include "opal/util/arch.h"
#include "opal/util/argv.h"
#include "opal/util/output.h"

Просмотреть файл

@ -8,7 +8,7 @@
* reserved.
* Copyright (c) 2014-2018 Cisco Systems, Inc. All rights reserved
* Copyright (c) 2018 Amazon.com, Inc. or its affiliates. All Rights reserved.
* Copyright (c) 2018 Triad National Security, LLC. All rights
* Copyright (c) 2018-2020 Triad National Security, LLC. All rights
* reserved.
* Copyright (c) 2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
@ -46,8 +46,7 @@
#include "opal/util/string_copy.h"
#include "opal/mca/hwloc/base/base.h"
#include "opal/mca/pmix/base/base.h"
#include "opal/threads/threads.h"
#include "opal/threads/tsd.h"
#include "opal/mca/threads/tsd.h"
#include "opal/class/opal_list.h"
#include "opal/dss/dss.h"

Просмотреть файл

@ -6,6 +6,8 @@
* Copyright (c) 2014-2020 Intel, Inc. All rights reserved.
* Copyright (c) 2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2020 Triad National Security, LLC. All rights
* reserved.
*
* $COPYRIGHT$
*
@ -169,7 +171,7 @@
struct opal_proc_t;
#include "opal/threads/threads.h"
#include "opal/mca/threads/threads.h"
#include "opal/util/proc.h"
#include "opal/mca/hwloc/hwloc-internal.h"
#include "opal/mca/pmix/pmix-internal.h"

Просмотреть файл

@ -71,7 +71,6 @@ endif
include class/Makefile.am
include memoryhooks/Makefile.am
include runtime/Makefile.am
include threads/Makefile.am
include mca/Makefile.am
include tools/Makefile.am
include dss/Makefile.am

Просмотреть файл

@ -28,7 +28,7 @@
#include "opal/class/opal_lifo.h"
#include "opal/sys/atomic.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
BEGIN_C_DECLS

Просмотреть файл

@ -27,7 +27,7 @@
#include "opal_config.h"
#include "opal/class/opal_lifo.h"
#include "opal/prefetch.h"
#include "opal/threads/condition.h"
#include "opal/mca/threads/condition.h"
#include "opal/constants.h"
#include "opal/runtime/opal.h"

Просмотреть файл

@ -31,7 +31,7 @@
#include "opal/class/opal_list.h"
#include "opal/sys/atomic.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
BEGIN_C_DECLS

Просмотреть файл

@ -75,7 +75,7 @@
#if OPAL_ENABLE_DEBUG
/* Need atomics for debugging (reference counting) */
#include "opal/sys/atomic.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#endif
BEGIN_C_DECLS

Просмотреть файл

@ -123,7 +123,7 @@
#include <assert.h>
#include <stdlib.h>
#include "opal/threads/thread_usage.h"
#include "opal/mca/threads/thread_usage.h"
BEGIN_C_DECLS

Просмотреть файл

@ -31,7 +31,7 @@
#include "opal_config.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/class/opal_object.h"
#include "opal/prefetch.h"

Просмотреть файл

@ -26,7 +26,7 @@
#include "opal_config.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/threads.h"
#include "opal/class/opal_object.h"
#include "opal/util/output.h"

Просмотреть файл

@ -67,7 +67,7 @@
#if OPAL_ENABLE_DEBUG
/* Need atomics for debugging (reference counting) */
#include "opal/sys/atomic.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#endif
BEGIN_C_DECLS

Просмотреть файл

@ -29,7 +29,7 @@
#include "opal_config.h"
#include <stdlib.h>
#include <string.h>
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/class/opal_free_list.h"
#include "opal/mca/allocator/allocator.h"

Просмотреть файл

@ -29,7 +29,7 @@
#include "opal_config.h"
#include <stdlib.h>
#include <string.h>
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/mca/allocator/allocator.h"
BEGIN_C_DECLS

Просмотреть файл

@ -14,7 +14,7 @@
#ifndef BTL_OFI_RDMA_H
#define BTL_OFI_RDMA_H
#include "opal/threads/thread_usage.h"
#include "opal/mca/threads/thread_usage.h"
#include "btl_ofi.h"
#include "btl_ofi_endpoint.h"

Просмотреть файл

@ -79,7 +79,7 @@
#include "opal/mca/btl/base/btl_base_error.h"
#include "opal/mca/reachable/base/base.h"
#include "opal/mca/pmix/pmix-internal.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/threads.h"
#include "opal/constants.h"
#include "opal/mca/btl/btl.h"

Просмотреть файл

@ -39,7 +39,7 @@
#include "opal/class/opal_fifo.h"
#include "opal/class/opal_hash_table.h"
#include "opal/mca/pmix/pmix-internal.h"
#include "opal/threads/tsd.h"
#include "opal/mca/threads/tsd.h"
#include <uct/api/uct.h>
#include "btl_uct_types.h"

Просмотреть файл

@ -22,7 +22,7 @@
#endif
#include "opal_stdint.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/mca/event/event.h"
#include "opal/util/show_help.h"
#include "opal/types.h"

Просмотреть файл

@ -25,7 +25,7 @@
#include <time.h>
#include "opal_stdint.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/mca/event/event.h"
#include "opal/util/output.h"
#include "opal/util/fd.h"

Просмотреть файл

@ -33,7 +33,7 @@
#include "opal/util/output.h"
#include "opal/util/show_help.h"
#include "opal/util/printf.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/mca/btl/base/btl_base_error.h"
#include "btl_vader.h"

Просмотреть файл

@ -15,7 +15,7 @@
#include "opal/runtime/opal_progress.h"
#include "opal/include/opal/constants.h"
#include "opal/class/opal_list.h"
#include "opal/threads/tsd.h"
#include "opal/mca/threads/tsd.h"
BEGIN_C_DECLS

Просмотреть файл

@ -48,6 +48,8 @@ BEGIN_C_DECLS
#define OPAL_TIMEOUT_DEFAULT {1, 0}
OPAL_DECLSPEC void opal_event_use_threads(void);
/**
* Structure for event components.
*/

3
opal/mca/event/external/external.h поставляемый
Просмотреть файл

@ -71,9 +71,6 @@ OPAL_DECLSPEC int opal_event_finalize(void);
#define opal_event_set_priority(x, n) event_priority_set((x), (n))
/* thread support APIs */
#define opal_event_use_threads() evthread_use_pthreads()
/* Basic event APIs */
#define opal_event_enable_debug_mode() event_enable_debug_mode()

Просмотреть файл

@ -48,8 +48,8 @@
#include <time.h>
#include "opal/class/opal_object.h"
#include "opal/threads/mutex.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/mutex.h"
#include "opal/mca/threads/threads.h"
#include "opal/util/output.h"
#include "opal/constants.h"
#include "opal/util/argv.h"
@ -102,9 +102,6 @@ OPAL_DECLSPEC int opal_event_finalize(void);
#define opal_event_set_priority(x, n) event_priority_set((x), (n))
/* thread support APIs */
#define opal_event_use_threads() evthread_use_pthreads()
/* Basic event APIs */
#define opal_event_enable_debug_mode() event_enable_debug_mode()

Просмотреть файл

@ -53,8 +53,8 @@
#include <time.h>
#include "opal/class/opal_object.h"
#include "opal/threads/mutex.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/mutex.h"
#include "opal/mca/threads/threads.h"
#include "opal/util/output.h"
#include "opal/util/argv.h"
#include "opal/util/fd.h"

Просмотреть файл

@ -21,7 +21,7 @@
#include "opal/util/show_help.h"
#include "opal/mca/mca.h"
#include "opal/mca/base/base.h"
#include "opal/threads/tsd.h"
#include "opal/mca/threads/tsd.h"
#include "opal/mca/hwloc/hwloc-internal.h"
#include "opal/mca/hwloc/base/base.h"

Просмотреть файл

@ -55,8 +55,8 @@
#include "opal/util/os_dirpath.h"
#include "opal/util/show_help.h"
#include "opal/util/printf.h"
#include "opal/threads/tsd.h"
#include "opal/mca/pmix/pmix-internal.h"
#include "opal/mca/threads/tsd.h"
#include "opal/mca/hwloc/hwloc-internal.h"
#include "opal/mca/hwloc/base/base.h"

Просмотреть файл

@ -29,7 +29,7 @@
#include "opal/mca/mpool/mpool.h"
#include "base.h"
#include "mpool_base_tree.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/util/info.h"
#include "opal/align.h"

Просмотреть файл

@ -18,7 +18,7 @@
#include "opal/mca/patcher/patcher.h"
#include "opal/class/opal_list.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
struct mca_patcher_linux_patch_got_t {
opal_list_item_t super;

Просмотреть файл

@ -1,5 +1,7 @@
/*
* Copyright (c) 2014-2019 Intel, Inc. All rights reserved.
* Copyright (c) 2020 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -14,7 +16,7 @@
#include "opal_config.h"
#include "opal/types.h"
#include "opal/threads/threads.h"
#include "opal/mca/threads/threads.h"
#include "opal/mca/mca.h"
#include "opal/mca/base/mca_base_framework.h"

Просмотреть файл

@ -13,7 +13,7 @@
#include "opal/constants.h"
#include "opal/mca/mca.h"
#include "opal/threads/thread_usage.h"
#include "opal/mca/threads/thread_usage.h"
#include "opal/util/argv.h"
#include "opal/util/output.h"
#include "opal/mca/base/base.h"

Просмотреть файл

@ -5,6 +5,8 @@
* reserved.
* Copyright (c) 2019 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2020 Triad National Security, LLC. All rights
* reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -24,6 +26,7 @@
#include "opal/mca/mca.h"
#include "opal/mca/event/event.h"
#include "opal/mca/threads/threads.h"
#include "opal/dss/dss.h"
#include "opal/runtime/opal.h"
#include "opal/dss/dss.h"
@ -61,21 +64,23 @@ typedef struct {
} opal_info_item_t;
OBJ_CLASS_DECLARATION(opal_info_item_t);
typedef opal_cond_t opal_pmix_condition_t;
typedef struct {
opal_mutex_t mutex;
pthread_cond_t cond;
opal_pmix_condition_t cond;
volatile bool active;
int status;
char *msg;
} opal_pmix_lock_t;
#define opal_pmix_condition_wait(a,b) pthread_cond_wait(a, &(b)->m_lock_pthread)
#define opal_pmix_condition_wait(a,b) opal_cond_wait(a, b)
#define opal_pmix_condition_broadcast(a) opal_cond_broadcast(a)
#define OPAL_PMIX_CONSTRUCT_LOCK(l) \
do { \
OBJ_CONSTRUCT(&(l)->mutex, opal_mutex_t); \
pthread_cond_init(&(l)->cond, NULL); \
opal_cond_init(&(l)->cond); \
(l)->active = true; \
(l)->status = 0; \
(l)->msg = NULL; \
@ -86,7 +91,7 @@ typedef struct {
do { \
OPAL_ACQUIRE_OBJECT((l)); \
OBJ_DESTRUCT(&(l)->mutex); \
pthread_cond_destroy(&(l)->cond); \
opal_cond_destroy(&(l)->cond); \
if (NULL != (l)->msg) { \
free((l)->msg); \
} \
@ -161,7 +166,7 @@ typedef struct {
__FILE__, __LINE__); \
} \
(lck)->active = false; \
pthread_cond_broadcast(&(lck)->cond); \
opal_pmix_condition_broadcast(&(lck)->cond); \
opal_mutex_unlock(&(lck)->mutex); \
} while(0)
#else
@ -169,18 +174,17 @@ typedef struct {
do { \
assert(0 != opal_mutex_trylock(&(lck)->mutex)); \
(lck)->active = false; \
pthread_cond_broadcast(&(lck)->cond); \
opal_pmix_condition_broadcast(&(lck)->cond); \
opal_mutex_unlock(&(lck)->mutex); \
} while(0)
#endif
#define OPAL_PMIX_WAKEUP_THREAD(lck) \
do { \
opal_mutex_lock(&(lck)->mutex); \
(lck)->active = false; \
OPAL_POST_OBJECT(lck); \
pthread_cond_broadcast(&(lck)->cond); \
opal_pmix_condition_broadcast(&(lck)->cond); \
opal_mutex_unlock(&(lck)->mutex); \
} while(0)

Просмотреть файл

@ -27,7 +27,7 @@
#define MCA_RCACHE_H
#include "opal/mca/mca.h"
#include "opal/mca/mpool/mpool.h"
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
/* forward-declaration of rcache module structure */

47
opal/mca/threads/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,47 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2010-2020 Cisco Systems, Inc. All rights reserved
# Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# main library setup
noinst_LTLIBRARIES = libmca_threads.la
libmca_threads_la_SOURCES =
# local files
headers = \
condition.h \
mutex.h \
thread.h \
threads.h \
thread_usage.h \
tsd.h \
wait_sync.h
nodist_headers =
libmca_threads_la_SOURCES += $(headers)
# Conditionally install the header files
if WANT_INSTALL_HEADERS
opaldir = $(opalincludedir)/$(subdir)
nobase_opal_HEADERS = $(headers)
nobase_nodist_opal_HEADERS = $(nodist_headers)
endif
include base/Makefile.am
distclean-local:
rm -f base/static-components.h

41
opal/mca/threads/README.md Обычный файл
Просмотреть файл

@ -0,0 +1,41 @@
# MCA THREADING FRAMEWORK
This MCA framework makes it possible to integrate new threading frameworks with the Open MPI runtime.
## BACKGROUND
There has been a lot of interest in integrating alternative threading models, in particular lightweight threading models with MPI implementations. Open MPI's modular component architecture seems like an ideal architecture for this sort of integration (in fact it was, Open MPI used to support Solaris and Windows threads).
Recently there has been interest in integrating MPI with lightweight tasking layers, which led to work reviving and modernizing the old modular threading code but with an emphasis on integrating lightweight threading models.
## SELECTING A THREADING MODEL
The threading model is chosen via the configure option `--with-threads=<threading_model>`. This will choose a compile time threading model as well as compiling the relevant MCA.
## IMPLEMENTATION
The MCA for threading libraries is implemented in two places, once as a set of `.h` files in `mca/threads/<threading_model>/threads_<threading_model>_{threads,mutex,tsd}.h` which are defined inline to the main thread implementation and also as an MCA component that is loaded at runtime.
For performance reasons, in particular synchronization overhead, it is not possible to implement a threading model as a traditional MCA. This means --at least in the short term-- that threading models are chosen at compile time rather than runtime options, using mechanisms similar to Open MPI's libevent integration.
The .h files are meant to be run on the fast path containing inline synchonization functions (threads_<threading_model>_mutex.h, thread local storage (threads_<threading_model>_tsd.h) and the opal_thread structure (threads_<threading_model>_thread.h).
The rest of the threading implementation follows the normal MCA model:
* `threads_<threading_model>_component.c` describes the version of the module and specifies the module open behavior (the threading model initialization goes here).
* `threads_<threading_model>_condition.c` defines an instance of `opal_condition_t` which is used by `condition.h` to define Open MPI specific condition variables.
* `threads_<threading_model>_event.c` defines an interface to Open MPI's libevent hooks. It allows the threading module to use threading model specific memory allocation and synchronization structures with Open MPI's libevent integration.
* `threads_<threading_model>_module.c` defines the interface to opal's thread handle. It provides ways of comparing threads, getting the value of a thread via its handle and the implementation of thread local storage.
* `threads_<threading_model>_mutex.c` provides a slow path interface to creating and destroying mutices dynamically via mca allocation. They can also be defined statically using the `.h` fast path interface.
* `threads_<threading_model>_wait_sync.c` provides condition variable like waiting capability that ensures MPI progress while it waits.
## TODO
Libevent integration with lightweight threading models is a work in progress. The current Open MPI libevent library assumes preemption and does not yield by default. Lightweight threading libraries typically require tasks to be cooperative and to voluntarily yield after some time.
Open MPI itself needs to be altered to use a common yielding model instead of usleep(3).

36
opal/mca/threads/argobots/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,36 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
noinst_LTLIBRARIES = libmca_threads_argobots.la
libmca_threads_argobots_la_SOURCES = \
threads_argobots.h \
threads_argobots_component.c \
threads_argobots_condition.c \
threads_argobots_event.c \
threads_argobots_module.c \
threads_argobots_mutex.c \
threads_argobots_mutex.h \
threads_argobots_threads.h \
threads_argobots_tsd.h \
threads_argobots_wait_sync.c \
threads_argobots_wait_sync.h
AM_LDFLAGS = -labt

81
opal/mca/threads/argobots/configure.m4 Обычный файл
Просмотреть файл

@ -0,0 +1,81 @@
# -*- shell-script -*-
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2015 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
# Copyright (c) 2019 Triad National Security, LLC. All rights
# Reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
AC_DEFUN([OPAL_CONFIG_ARGOBOTS_THREADS],[
AC_CHECK_HEADERS([abt.h],
[AC_CHECK_LIB([abt],[ABT_init],
[threads_argobots_happy="yes"],
[threads_argobots_happy="no"])],
[threads_argobots_happy="no"])
AS_IF([test "$threads_argobots_happy" = "yes"],
[$1],
[$2])
])dnl
AC_DEFUN([MCA_opal_threads_argobots_PRIORITY], [30])
AC_DEFUN([MCA_opal_threads_argobots_COMPILE_MODE], [
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
$4="static"
AC_MSG_RESULT([$$4])
])
# If component was selected, $1 will be 1 and we should set the base header
AC_DEFUN([MCA_opal_threads_argobots_POST_CONFIG],[
AS_IF([test "$1" = "1"],
[opal_thread_type_found="argobots"
AC_DEFINE_UNQUOTED([MCA_threads_base_include_HEADER],
["opal/mca/threads/argobots/threads_argobots_threads.h"],
[Header to include for threads implementation])
AC_DEFINE_UNQUOTED([MCA_threads_mutex_base_include_HEADER],
["opal/mca/threads/argobots/threads_argobots_mutex.h"],
[Header to include for mutex implementation])
AC_DEFINE_UNQUOTED([MCA_threads_tsd_base_include_HEADER],
["opal/mca/threads/argobots/threads_argobots_tsd.h"],
[Header to include for tsd implementation])
AC_DEFINE_UNQUOTED([MCA_threads_wait_sync_base_include_HEADER],
["opal/mca/threads/argobots/threads_argobots_wait_sync.h"],
[Header to include for wait_sync implementation])
])
])dnl
# MCA_threads_argobots_CONFIG(action-if-can-compile,
# [action-if-cant-compile])
# ------------------------------------------------
AC_DEFUN([MCA_opal_threads_argobots_CONFIG],[
AC_CONFIG_FILES([opal/mca/threads/argobots/Makefile])
AS_IF([test "$with_threads" = "argobots"],
[OPAL_CONFIG_ARGOBOTS_THREADS([argobots_threads_works=1], [argobots_threads_works=0])],
[argobots_threads_works=0])
AS_IF([test "$argobots_threads_works" = "1"],
[$1
opal_thread_type_found="argobots"],
[$2])
])

7
opal/mca/threads/argobots/owner.txt Обычный файл
Просмотреть файл

@ -0,0 +1,7 @@
#
# owner/status file
# owner: institution that is responsible for this package
# status: e.g. active, maintenance, unmaintained
#
owner: SNL
status: active

Просмотреть файл

@ -0,0 +1,38 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H
#include <abt.h>
static inline void opal_threads_argobots_ensure_init(void)
{
if (ABT_SUCCESS != ABT_initialized()) {
ABT_init(0, 0);
}
}
#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_H */

Просмотреть файл

@ -0,0 +1,57 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2014 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2015 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/mca/threads/argobots/threads_argobots.h"
#include "opal/mca/threads/thread.h"
#include "opal/mca/threads/threads.h"
#include "opal/constants.h"
#include <abt.h>
static int opal_threads_argobots_open(void);
const opal_threads_base_component_1_0_0_t mca_threads_argobots_component = {
/* First, the mca_component_t struct containing meta information
* about the component itself */
.threadsc_version = {
OPAL_THREADS_BASE_VERSION_1_0_0,
/* Component name and version */
.mca_component_name = "argobots",
MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION),
.mca_open_component = opal_threads_argobots_open,
},
.threadsc_data = {
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
};
int opal_threads_argobots_open(void)
{
opal_threads_argobots_ensure_init();
return OPAL_SUCCESS;
}

Просмотреть файл

@ -0,0 +1,39 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/mca/threads/condition.h"
static void opal_condition_construct(opal_condition_t *c)
{
c->c_waiting = 0;
c->c_signaled = 0;
}
static void opal_condition_destruct(opal_condition_t *c)
{
}
OBJ_CLASS_INSTANCE(opal_condition_t,
opal_object_t,
opal_condition_construct,
opal_condition_destruct);

Просмотреть файл

@ -0,0 +1,143 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal/mca/threads/threads.h"
#include "opal/mca/threads/argobots/threads_argobots.h"
#include "opal/mca/event/libevent2022/libevent/include/event2/thread.h"
#include "opal/mca/event/libevent2022/libevent/include/event2/event-config.h"
#include "opal/mca/event/libevent2022/libevent/include/event2/util.h"
#include <abt.h>
static void *evthread_argobots_lock_alloc(unsigned locktype)
{
ABT_mutex lock;
if (locktype & EVTHREAD_LOCKTYPE_RECURSIVE) {
ABT_mutex_attr abt_mutex_attr;
ABT_mutex_attr_create(&abt_mutex_attr);
ABT_mutex_attr_set_recursive(abt_mutex_attr, ABT_TRUE);
ABT_mutex_create_with_attr(abt_mutex_attr, &lock);
ABT_mutex_attr_free(&abt_mutex_attr);
} else {
ABT_mutex_create(&lock);
}
return lock;
}
static void evthread_argobots_lock_free(void *_lock, unsigned locktype)
{
ABT_mutex lock = _lock;
ABT_mutex_free(&lock);
}
static int evthread_argobots_lock(unsigned mode, void *_lock)
{
int ret;
ABT_mutex lock = _lock;
if (mode & EVTHREAD_TRY) {
ret = ABT_mutex_trylock(lock);
} else {
ret = ABT_mutex_lock(lock);
}
return ABT_SUCCESS == ret ? 0 : -1;
}
static int evthread_argobots_unlock(unsigned mode, void *_lock)
{
ABT_mutex lock = _lock;
int ret = ABT_mutex_unlock(lock);
/* This yield is necessary to avoid taking a lock consecutively. */
ABT_thread_yield();
return ABT_SUCCESS == ret ? 0 : -1;
}
static unsigned long evthread_argobots_get_id(void)
{
ABT_thread thr;
ABT_thread_self(&thr);
return (unsigned long)((intptr_t)thr);
}
static void *evthread_argobots_cond_alloc(unsigned condflags)
{
ABT_cond cond;
ABT_cond_create(&cond);
return cond;
}
static void evthread_argobots_cond_free(void *_cond)
{
ABT_cond cond = _cond;
ABT_cond_free(&cond);
}
static int evthread_argobots_cond_signal(void *_cond, int broadcast)
{
ABT_cond cond = _cond;
int ret;
if (broadcast) {
ret = ABT_cond_broadcast(cond);
} else {
ret = ABT_cond_signal(cond);
}
return ABT_SUCCESS == ret ? 0 : -1;
}
static int evthread_argobots_cond_wait(void *_cond, void *_lock,
const struct timeval *tv)
{
int ret;
ABT_cond cond = _cond;
ABT_mutex lock = _lock;
if (tv) {
struct timeval now, abstime;
struct timespec ts;
evutil_gettimeofday(&now, NULL);
evutil_timeradd(&now, tv, &abstime);
ts.tv_sec = abstime.tv_sec;
ts.tv_nsec = abstime.tv_usec * 1000;
ret = ABT_cond_timedwait(cond, lock, &ts);
if (ABT_ERR_COND_TIMEDOUT == ret) {
return 1;
} else if (ABT_SUCCESS != ret) {
return -1;
} else {
return 0;
}
} else {
ret = ABT_cond_wait(cond, lock);
return ABT_SUCCESS == ret ? 0 : -1;
}
}
void opal_event_use_threads(void)
{
struct evthread_lock_callbacks cbs = {
EVTHREAD_LOCK_API_VERSION,
EVTHREAD_LOCKTYPE_RECURSIVE,
evthread_argobots_lock_alloc,
evthread_argobots_lock_free,
evthread_argobots_lock,
evthread_argobots_unlock
};
struct evthread_condition_callbacks cond_cbs = {
EVTHREAD_CONDITION_API_VERSION,
evthread_argobots_cond_alloc,
evthread_argobots_cond_free,
evthread_argobots_cond_signal,
evthread_argobots_cond_wait
};
opal_threads_argobots_ensure_init();
evthread_set_lock_callbacks(&cbs);
evthread_set_condition_callbacks(&cond_cbs);
evthread_set_id_callback(evthread_argobots_get_id);
}

Просмотреть файл

@ -0,0 +1,158 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* Copyright (c) 2020 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include <unistd.h>
#include "opal/mca/threads/argobots/threads_argobots.h"
#include "opal/constants.h"
#include "opal/util/sys_limits.h"
#include "opal/util/output.h"
#include "opal/prefetch.h"
#include "opal/mca/threads/threads.h"
#include "opal/mca/threads/tsd.h"
#include <abt.h>
struct opal_tsd_key_value {
opal_tsd_key_t key;
opal_tsd_destructor_t destructor;
};
static ABT_thread opal_main_thread;
struct opal_tsd_key_value *opal_tsd_key_values = NULL;
static int opal_tsd_key_values_count = 0;
/*
* Constructor
*/
static void opal_thread_construct(opal_thread_t *t)
{
t->t_run = 0;
t->t_handle = ABT_THREAD_NULL;
}
OBJ_CLASS_INSTANCE(opal_thread_t,
opal_object_t,
opal_thread_construct, NULL);
static inline ABT_thread opal_thread_get_argobots_self(void)
{
ABT_thread self;
ABT_thread_self(&self);
return self;
}
static void opal_thread_argobots_wrapper(void *arg)
{
opal_thread_t *t = (opal_thread_t *)arg;
t->t_ret = ((void *(*)(void *))t->t_run)(t);
}
opal_thread_t *opal_thread_get_self(void)
{
opal_threads_argobots_ensure_init();
opal_thread_t *t = OBJ_NEW(opal_thread_t);
t->t_handle = opal_thread_get_argobots_self();
return t;
}
bool opal_thread_self_compare(opal_thread_t *t)
{
opal_threads_argobots_ensure_init();
return opal_thread_get_argobots_self() == t->t_handle;
}
int opal_thread_join(opal_thread_t *t, void **thr_return)
{
int rc = ABT_thread_free(&t->t_handle);
if (thr_return) {
*thr_return = t->t_ret;
}
t->t_handle = ABT_THREAD_NULL;
return (ABT_SUCCESS == rc) ? OPAL_SUCCESS : OPAL_ERROR;
}
void opal_thread_set_main()
{
opal_threads_argobots_ensure_init();
opal_main_thread = opal_thread_get_argobots_self();
}
int opal_thread_start(opal_thread_t *t)
{
opal_threads_argobots_ensure_init();
int rc;
if (OPAL_ENABLE_DEBUG) {
if (NULL == t->t_run || ABT_THREAD_NULL != t->t_handle) {
return OPAL_ERR_BAD_PARAM;
}
}
ABT_xstream self_xstream;
ABT_xstream_self(&self_xstream);
rc = ABT_thread_create_on_xstream(self_xstream,
opal_thread_argobots_wrapper, t,
ABT_THREAD_ATTR_NULL, &t->t_handle);
return (ABT_SUCCESS == rc) ? OPAL_SUCCESS : OPAL_ERROR;
}
OBJ_CLASS_DECLARATION(opal_thread_t);
int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor)
{
opal_threads_argobots_ensure_init();
int rc;
rc = ABT_key_create(destructor, key);
if ((ABT_SUCCESS == rc) &&
(opal_thread_get_argobots_self() == opal_main_thread)) {
opal_tsd_key_values = (struct opal_tsd_key_value *)
realloc(opal_tsd_key_values, (opal_tsd_key_values_count + 1) *
sizeof(struct opal_tsd_key_value));
opal_tsd_key_values[opal_tsd_key_values_count].key = *key;
opal_tsd_key_values[opal_tsd_key_values_count].destructor = destructor;
opal_tsd_key_values_count++;
}
return (ABT_SUCCESS == rc) ? OPAL_SUCCESS : OPAL_ERROR;
}
int opal_tsd_keys_destruct(void)
{
int i;
void *ptr;
for (i = 0; i < opal_tsd_key_values_count; i++) {
if (OPAL_SUCCESS ==
opal_tsd_getspecific(opal_tsd_key_values[i].key, &ptr)) {
if (NULL != opal_tsd_key_values[i].destructor) {
opal_tsd_key_values[i].destructor(ptr);
opal_tsd_setspecific(opal_tsd_key_values[i].key, NULL);
}
}
}
if (0 < opal_tsd_key_values_count) {
free(opal_tsd_key_values);
opal_tsd_key_values_count = 0;
}
return OPAL_SUCCESS;
}

Просмотреть файл

@ -0,0 +1,174 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal/mca/threads/argobots/threads_argobots.h"
#include "opal_config.h"
#include <errno.h>
#include "opal/mca/threads/mutex.h"
#include "opal/mca/threads/argobots/threads_argobots_mutex.h"
#include "opal/constants.h"
/*
* Wait and see if some upper layer wants to use threads, if support
* exists.
*/
bool opal_uses_threads = false;
static void mca_threads_argobots_mutex_constructor(opal_mutex_t *p_mutex)
{
opal_threads_argobots_ensure_init();
p_mutex->m_lock_argobots = OPAL_ABT_MUTEX_NULL;
p_mutex->m_recursive = 0;
#if OPAL_ENABLE_DEBUG
p_mutex->m_lock_debug = 0;
p_mutex->m_lock_file = NULL;
p_mutex->m_lock_line = 0;
#endif
opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0);
}
static void mca_threads_argobots_mutex_destructor(opal_mutex_t *p_mutex)
{
if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) {
ABT_mutex_free(&p_mutex->m_lock_argobots);
}
}
static void mca_threads_argobots_recursive_mutex_constructor
(opal_recursive_mutex_t *p_mutex)
{
opal_threads_argobots_ensure_init();
p_mutex->m_lock_argobots = OPAL_ABT_MUTEX_NULL;
p_mutex->m_recursive = 1;
#if OPAL_ENABLE_DEBUG
p_mutex->m_lock_debug = 0;
p_mutex->m_lock_file = NULL;
p_mutex->m_lock_line = 0;
#endif
opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0);
}
static void mca_threads_argobots_recursive_mutex_destructor
(opal_recursive_mutex_t *p_mutex)
{
if (OPAL_ABT_MUTEX_NULL != p_mutex->m_lock_argobots) {
ABT_mutex_free(&p_mutex->m_lock_argobots);
}
}
OBJ_CLASS_INSTANCE(opal_mutex_t,
opal_object_t,
mca_threads_argobots_mutex_constructor,
mca_threads_argobots_mutex_destructor);
OBJ_CLASS_INSTANCE(opal_recursive_mutex_t,
opal_object_t,
mca_threads_argobots_recursive_mutex_constructor,
mca_threads_argobots_recursive_mutex_destructor);
void opal_mutex_create(struct opal_mutex_t *m)
{
opal_threads_argobots_ensure_init();
while (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) {
ABT_mutex abt_mutex;
if (m->m_recursive) {
ABT_mutex_attr abt_mutex_attr;
ABT_mutex_attr_create(&abt_mutex_attr);
ABT_mutex_attr_set_recursive(abt_mutex_attr, ABT_TRUE);
ABT_mutex_create_with_attr(abt_mutex_attr, &abt_mutex);
ABT_mutex_attr_free(&abt_mutex_attr);
} else {
ABT_mutex_create(&abt_mutex);
}
void *null_ptr = OPAL_ABT_MUTEX_NULL;
if (opal_atomic_compare_exchange_strong_ptr(
(intptr_t *)&m->m_lock_argobots, (intptr_t *)&null_ptr,
(intptr_t)abt_mutex)) {
/* mutex is successfully created and substituted. */
return;
}
ABT_mutex_free(&abt_mutex);
}
}
static void opal_cond_create(opal_cond_t *cond)
{
opal_threads_argobots_ensure_init();
while (OPAL_ABT_COND_NULL == *cond) {
ABT_cond new_cond;
ABT_cond_create(&new_cond);
void *null_ptr = OPAL_ABT_COND_NULL;
if (opal_atomic_compare_exchange_strong_ptr((intptr_t *)cond,
(intptr_t *)&null_ptr,
(intptr_t)new_cond)) {
/* cond is successfully created and substituted. */
return;
}
ABT_cond_free(&new_cond);
}
}
int opal_cond_init(opal_cond_t *cond)
{
*cond = OPAL_ABT_COND_NULL;
return OPAL_SUCCESS;
}
int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock)
{
if (OPAL_ABT_COND_NULL == *cond) {
opal_cond_create(cond);
}
int ret = ABT_cond_wait(*cond, lock->m_lock_argobots);
return ABT_SUCCESS == ret ? OPAL_SUCCESS : OPAL_ERROR;
}
int opal_cond_broadcast(opal_cond_t *cond)
{
if (OPAL_ABT_COND_NULL == *cond) {
opal_cond_create(cond);
}
int ret = ABT_cond_broadcast(*cond);
return ABT_SUCCESS == ret ? OPAL_SUCCESS : OPAL_ERROR;
}
int opal_cond_signal(opal_cond_t *cond)
{
if (OPAL_ABT_COND_NULL == *cond) {
opal_cond_create(cond);
}
int ret = ABT_cond_signal(*cond);
return ABT_SUCCESS == ret ? OPAL_SUCCESS : OPAL_ERROR;
}
int opal_cond_destroy(opal_cond_t *cond)
{
int ret = ABT_SUCCESS;
if (OPAL_ABT_COND_NULL != *cond) {
ret = ABT_cond_free(cond);
}
return ABT_SUCCESS == ret ? OPAL_SUCCESS : OPAL_ERROR;
}

Просмотреть файл

@ -0,0 +1,229 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
* Copyright (c) 2020 Triad National Security, LLC. All rights
* reserved.
*
* Copyright (c) 2020 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H
#include "opal_config.h"
#include <errno.h>
#include <stdio.h>
#include "opal/mca/threads/argobots/threads_argobots.h"
#include "opal/class/opal_object.h"
#include "opal/sys/atomic.h"
#include "opal/util/output.h"
#include <abt.h>
BEGIN_C_DECLS
/* Don't use ABT_MUTEX_NULL, since it might be not NULL. */
#define OPAL_ABT_MUTEX_NULL 0
struct opal_mutex_t {
opal_object_t super;
ABT_mutex m_lock_argobots;
int m_recursive;
#if OPAL_ENABLE_DEBUG
int m_lock_debug;
const char *m_lock_file;
int m_lock_line;
#endif
opal_atomic_lock_t m_lock_atomic;
};
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);
#if OPAL_ENABLE_DEBUG
#define OPAL_MUTEX_STATIC_INIT \
{ \
.super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
.m_lock_argobots = OPAL_ABT_MUTEX_NULL, \
.m_recursive = 0, \
.m_lock_debug = 0, \
.m_lock_file = NULL, \
.m_lock_line = 0, \
.m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
}
#else
#define OPAL_MUTEX_STATIC_INIT \
{ \
.super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
.m_lock_argobots = OPAL_ABT_MUTEX_NULL, \
.m_recursive = 0, \
.m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
}
#endif
#if OPAL_ENABLE_DEBUG
#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \
{ \
.super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
.m_lock_argobots = OPAL_ABT_MUTEX_NULL, \
.m_recursive = 1, \
.m_lock_debug = 0, \
.m_lock_file = NULL, \
.m_lock_line = 0, \
.m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
}
#else
#define OPAL_RECURSIVE_MUTEX_STATIC_INIT \
{ \
.super = OPAL_OBJ_STATIC_INIT(opal_mutex_t), \
.m_lock_argobots = OPAL_ABT_MUTEX_NULL, \
.m_recursive = 1, \
.m_lock_atomic = OPAL_ATOMIC_LOCK_INIT, \
}
#endif
/************************************************************************
*
* mutex operations (non-atomic versions)
*
************************************************************************/
void opal_mutex_create(struct opal_mutex_t *m);
static inline int opal_mutex_trylock(opal_mutex_t *m)
{
if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) {
opal_mutex_create(m);
}
int ret = ABT_mutex_trylock(m->m_lock_argobots);
if (ABT_ERR_MUTEX_LOCKED == ret) {
return 1;
} else if (ABT_SUCCESS != ret) {
#if OPAL_ENABLE_DEBUG
opal_output(0, "opal_mutex_trylock()");
#endif
return 1;
}
return 0;
}
static inline void opal_mutex_lock(opal_mutex_t *m)
{
if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) {
opal_mutex_create(m);
}
#if OPAL_ENABLE_DEBUG
int ret = ABT_mutex_lock(m->m_lock_argobots);
if (ABT_SUCCESS != ret) {
opal_output(0, "opal_mutex_lock()");
}
#else
ABT_mutex_lock(m->m_lock_argobots);
#endif
}
static inline void opal_mutex_unlock(opal_mutex_t *m)
{
if (OPAL_ABT_MUTEX_NULL == m->m_lock_argobots) {
opal_mutex_create(m);
}
#if OPAL_ENABLE_DEBUG
int ret = ABT_mutex_unlock(m->m_lock_argobots);
if (ABT_SUCCESS != ret) {
opal_output(0, "opal_mutex_unlock()");
}
#else
ABT_mutex_unlock(m->m_lock_argobots);
#endif
/* For fairness of locking. */
ABT_thread_yield();
}
/************************************************************************
*
* mutex operations (atomic versions)
*
************************************************************************/
#if OPAL_HAVE_ATOMIC_SPINLOCKS
/************************************************************************
* Spin Locks
************************************************************************/
static inline int opal_mutex_atomic_trylock(opal_mutex_t *m)
{
return opal_atomic_trylock(&m->m_lock_atomic);
}
static inline void opal_mutex_atomic_lock(opal_mutex_t *m)
{
opal_atomic_lock(&m->m_lock_atomic);
}
static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
{
opal_atomic_unlock(&m->m_lock_atomic);
}
#else
/************************************************************************
* Standard locking
************************************************************************/
static inline int opal_mutex_atomic_trylock(opal_mutex_t *m)
{
return opal_mutex_trylock(m);
}
static inline void opal_mutex_atomic_lock(opal_mutex_t *m)
{
opal_mutex_lock(m);
}
static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
{
opal_mutex_unlock(m);
}
#endif
#define OPAL_ABT_COND_NULL NULL
typedef ABT_cond opal_cond_t;
#define OPAL_CONDITION_STATIC_INIT OPAL_ABT_COND_NULL
int opal_cond_init(opal_cond_t *cond);
int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock);
int opal_cond_broadcast(opal_cond_t *cond);
int opal_cond_signal(opal_cond_t *cond);
int opal_cond_destroy(opal_cond_t *cond);
END_C_DECLS
#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_MUTEX_H */

Просмотреть файл

@ -0,0 +1,40 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H
#include <abt.h>
#include <signal.h>
struct opal_thread_t {
opal_object_t super;
opal_thread_fn_t t_run;
void *t_arg;
ABT_thread t_handle;
void *t_ret;
};
#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_THREADS_H */

Просмотреть файл

@ -0,0 +1,54 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H
#include "opal/mca/threads/argobots/threads_argobots.h"
#include <abt.h>
typedef ABT_key opal_tsd_key_t;
static inline int opal_tsd_key_delete(opal_tsd_key_t key)
{
int ret = ABT_key_free(&key);
return ABT_SUCCESS == ret ? OPAL_SUCCESS : OPAL_ERROR;
}
static inline int opal_tsd_setspecific(opal_tsd_key_t key, void *value)
{
opal_threads_argobots_ensure_init();
int ret = ABT_key_set(key, value);
return ABT_SUCCESS == ret ? OPAL_SUCCESS : OPAL_ERROR;
}
static inline int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep)
{
int ret = ABT_key_get(key, valuep);
return ABT_SUCCESS == ret ? OPAL_SUCCESS : OPAL_ERROR;
}
#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_TSD_H */

Просмотреть файл

@ -0,0 +1,116 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2014-2016 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal/mca/threads/argobots/threads_argobots.h"
#include "opal/mca/threads/wait_sync.h"
static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT;
static ompi_wait_sync_t *wait_sync_list = NULL;
static opal_atomic_int32_t num_thread_in_progress = 0;
#define WAIT_SYNC_PASS_OWNERSHIP(who) \
do { \
ABT_mutex_lock((who)->lock); \
ABT_cond_signal((who)->condition ); \
ABT_mutex_unlock((who)->lock); \
} while (0)
int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
{
/* Don't stop if the waiting synchronization is completed. We avoid the
* race condition around the release of the synchronization using the
* signaling field.
*/
if (sync->count <= 0) {
return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR;
}
/* lock so nobody can signal us during the list updating */
ABT_mutex_lock(sync->lock);
/* Now that we hold the lock make sure another thread has not already
* call cond_signal.
*/
if (sync->count <= 0) {
ABT_mutex_unlock(sync->lock);
return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR;
}
/* Insert sync on the list of pending synchronization constructs */
OPAL_THREAD_LOCK(&wait_sync_lock);
if (NULL == wait_sync_list) {
sync->next = sync->prev = sync;
wait_sync_list = sync;
} else {
sync->prev = wait_sync_list->prev;
sync->prev->next = sync;
sync->next = wait_sync_list;
wait_sync_list->prev = sync;
}
OPAL_THREAD_UNLOCK(&wait_sync_lock);
/**
* If we are not responsible for progressing, go silent until something
* worth noticing happen:
* - this thread has been promoted to take care of the progress
* - our sync has been triggered.
*/
check_status:
if (sync != wait_sync_list &&
num_thread_in_progress >= opal_max_thread_in_progress) {
ABT_cond_wait(sync->condition, sync->lock);
/**
* At this point either the sync was completed in which case
* we should remove it from the wait list, or/and I was
* promoted as the progress manager.
*/
if (sync->count <= 0) { /* Completed? */
ABT_mutex_unlock(sync->lock);
goto i_am_done;
}
/* either promoted, or spurious wakeup ! */
goto check_status;
}
ABT_mutex_unlock(sync->lock);
OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, 1);
while (sync->count > 0) { /* progress till completion */
/* don't progress with the sync lock locked or you'll deadlock */
opal_progress();
ABT_thread_yield();
}
OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1);
i_am_done:
/* My sync is now complete. Trim the list: remove self, wake next */
OPAL_THREAD_LOCK(&wait_sync_lock);
sync->prev->next = sync->next;
sync->next->prev = sync->prev;
/* In case I am the progress manager, pass the duties on */
if (sync == wait_sync_list) {
wait_sync_list = (sync == sync->next) ? NULL : sync->next;
if (NULL != wait_sync_list) {
WAIT_SYNC_PASS_OWNERSHIP(wait_sync_list);
}
}
OPAL_THREAD_UNLOCK(&wait_sync_lock);
return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR;
}

Просмотреть файл

@ -0,0 +1,107 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H
#define OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H
#include "opal/mca/threads/argobots/threads_argobots.h"
#include <abt.h>
typedef struct ompi_wait_sync_t {
opal_atomic_int32_t count;
int32_t status;
ABT_cond condition;
ABT_mutex lock;
struct ompi_wait_sync_t *next;
struct ompi_wait_sync_t *prev;
volatile bool signaling;
} ompi_wait_sync_t;
#define SYNC_WAIT(sync) \
(opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync))
/* The loop in release handles a race condition between the signaling
* thread and the destruction of the condition variable. The signaling
* member will be set to false after the final signaling thread has
* finished operating on the sync object. This is done to avoid
* extra atomics in the signalling function and keep it as fast
* as possible. Note that the race window is small so spinning here
* is more optimal than sleeping since this macro is called in
* the critical path. */
#define WAIT_SYNC_RELEASE(sync) \
if (opal_using_threads()) { \
while ((sync)->signaling) { \
ABT_thread_yield(); \
continue; \
} \
ABT_cond_free(&(sync)->condition); \
ABT_mutex_free(&(sync)->lock); \
}
#define WAIT_SYNC_RELEASE_NOWAIT(sync) \
if (opal_using_threads()) { \
ABT_cond_free(&(sync)->condition); \
ABT_mutex_free(&(sync)->lock); \
}
#define WAIT_SYNC_SIGNAL(sync) \
if (opal_using_threads()) { \
ABT_mutex_lock(sync->lock); \
ABT_cond_signal(sync->condition); \
ABT_mutex_unlock(sync->lock); \
sync->signaling = false; \
}
#define WAIT_SYNC_SIGNALLED(sync) \
{ \
(sync)->signaling = false; \
}
OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync);
static inline int sync_wait_st(ompi_wait_sync_t *sync)
{
while (sync->count > 0) {
opal_progress();
ABT_thread_yield();
}
return sync->status;
}
#define WAIT_SYNC_INIT(sync,c) \
do { \
(sync)->count = (c); \
(sync)->next = NULL; \
(sync)->prev = NULL; \
(sync)->status = 0; \
(sync)->signaling = (0 != (c)); \
if (opal_using_threads()) { \
ABT_cond_create(&(sync)->condition); \
ABT_mutex_create(&(sync)->lock); \
} \
} while (0)
#endif /* OPAL_MCA_THREADS_ARGOBOTS_THREADS_ARGOBOTS_WAIT_SYNC_H */

25
opal/mca/threads/base/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,25 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
#
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
headers += \
base/base.h
libmca_threads_la_SOURCES += \
base/threads_base.c

48
opal/mca/threads/base/base.h Обычный файл
Просмотреть файл

@ -0,0 +1,48 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2014 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/
#ifndef OPAL_MCA_THREADS_BASE_BASE_H
#define OPAL_MCA_THREADS_BASE_BASE_H
#include "opal_config.h"
#include "opal/mca/base/mca_base_framework.h"
#include "opal/mca/threads/threads.h"
/*
* Global functions for MCA overall threads open and close
*/
BEGIN_C_DECLS
/**
* Framework structure declaration
*/
OPAL_DECLSPEC extern mca_base_framework_t opal_threads_base_framework;
END_C_DECLS
/* include implementation to call */
#include MCA_threads_base_include_HEADER
#endif /* OPAL_MCA_THREADS_BASE_BASE_H */

7
opal/mca/threads/base/owner.txt Обычный файл
Просмотреть файл

@ -0,0 +1,7 @@
#
# owner/status file
# owner: institution that is responsible for this package
# status: e.g. active, maintenance, unmaintained
#
owner: SNL
status: maintenance

50
opal/mca/threads/base/threads_base.c Обычный файл
Просмотреть файл

@ -0,0 +1,50 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2014 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2014 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/constants.h"
#include "opal/mca/threads/base/base.h"
#if OPAL_ENABLE_DEBUG
bool opal_debug_threads = false;
#endif
/*
* The following file was created by configure. It contains extern
* statements and the definition of an array of pointers to each
* component's public mca_base_component_t struct.
*/
#include "opal/mca/threads/base/static-components.h"
static int mca_threads_base_register(mca_base_register_flag_t flags)
{
return OPAL_SUCCESS;
}
/*
* Globals
*/
/* Use default register/open/close functions */
MCA_BASE_FRAMEWORK_DECLARE(opal, threads, "OPAL threads",
mca_threads_base_register, NULL, NULL,
mca_threads_base_static_components, 0);

Просмотреть файл

@ -1,3 +1,4 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
@ -13,14 +14,19 @@
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
* Copyright (c) 2019 Triad National Security, LLC. All rights
* reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_CONDITION_SPINLOCK_H
#define OPAL_CONDITION_SPINLOCK_H
#ifndef OPAL_MCA_THREADS_CONDITION_H
#define OPAL_MCA_THREADS_CONDITION_H
#include "opal_config.h"
#ifdef HAVE_SYS_TIME_H
@ -29,7 +35,7 @@
#include <time.h>
#include <pthread.h>
#include "opal/threads/mutex.h"
#include "opal/mca/threads/mutex.h"
#include "opal/runtime/opal_progress.h"
#include "opal/runtime/opal_cr.h"
@ -53,7 +59,7 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_condition_t);
static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m)
{
int rc = 0;
int rc = OPAL_SUCCESS;
c->c_waiting++;
if (opal_using_threads()) {
@ -63,16 +69,16 @@ static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m)
opal_progress();
OPAL_CR_TEST_CHECKPOINT_READY_STALL();
opal_mutex_lock(m);
return 0;
return rc;
}
while (c->c_signaled == 0) {
while (0 == c->c_signaled) {
opal_mutex_unlock(m);
opal_progress();
OPAL_CR_TEST_CHECKPOINT_READY_STALL();
opal_mutex_lock(m);
}
} else {
while (c->c_signaled == 0) {
while (0 == c->c_signaled) {
opal_progress();
OPAL_CR_TEST_CHECKPOINT_READY_STALL();
}
@ -83,44 +89,45 @@ static inline int opal_condition_wait(opal_condition_t *c, opal_mutex_t *m)
return rc;
}
static inline int opal_condition_timedwait(opal_condition_t *c,
opal_mutex_t *m,
static inline int opal_condition_timedwait(opal_condition_t *c, opal_mutex_t *m,
const struct timespec *abstime)
{
struct timeval tv;
struct timeval absolute;
int rc = 0;
int rc = OPAL_SUCCESS;
c->c_waiting++;
if (opal_using_threads()) {
absolute.tv_sec = abstime->tv_sec;
absolute.tv_usec = abstime->tv_nsec / 1000;
gettimeofday(&tv,NULL);
if (c->c_signaled == 0) {
gettimeofday(&tv, NULL);
if (0 == c->c_signaled) {
do {
opal_mutex_unlock(m);
opal_progress();
gettimeofday(&tv,NULL);
gettimeofday(&tv, NULL);
opal_mutex_lock(m);
} while (c->c_signaled == 0 &&
(tv.tv_sec <= absolute.tv_sec ||
(tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec)));
} while (0 == c->c_signaled && (tv.tv_sec <= absolute.tv_sec ||
(tv.tv_sec == absolute.tv_sec &&
tv.tv_usec < absolute.tv_usec)));
}
} else {
absolute.tv_sec = abstime->tv_sec;
absolute.tv_usec = abstime->tv_nsec / 1000;
gettimeofday(&tv,NULL);
if (c->c_signaled == 0) {
gettimeofday(&tv, NULL);
if (0 == c->c_signaled) {
do {
opal_progress();
gettimeofday(&tv,NULL);
} while (c->c_signaled == 0 &&
(tv.tv_sec <= absolute.tv_sec ||
(tv.tv_sec == absolute.tv_sec && tv.tv_usec < absolute.tv_usec)));
gettimeofday(&tv, NULL);
} while (0 == c->c_signaled && (tv.tv_sec <= absolute.tv_sec ||
(tv.tv_sec == absolute.tv_sec &&
tv.tv_usec < absolute.tv_usec)));
}
}
if (c->c_signaled != 0) c->c_signaled--;
if (0 != c->c_signaled) {
c->c_signaled--;
}
c->c_waiting--;
return rc;
}
@ -130,16 +137,15 @@ static inline int opal_condition_signal(opal_condition_t *c)
if (c->c_waiting) {
c->c_signaled++;
}
return 0;
return OPAL_SUCCESS;
}
static inline int opal_condition_broadcast(opal_condition_t *c)
{
c->c_signaled = c->c_waiting;
return 0;
return OPAL_SUCCESS;
}
END_C_DECLS
#endif
#endif /* OPAL_MCA_THREADS_CONDITION_H */

60
opal/mca/threads/configure.m4 Обычный файл
Просмотреть файл

@ -0,0 +1,60 @@
dnl -*- shell-script -*-
dnl
dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
dnl University Research and Technology
dnl Corporation. All rights reserved.
dnl Copyright (c) 2004-2005 The University of Tennessee and The University
dnl of Tennessee Research Foundation. All rights
dnl reserved.
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
dnl University of Stuttgart. All rights reserved.
dnl Copyright (c) 2004-2005 The Regents of the University of California.
dnl All rights reserved.
dnl Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
dnl Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
dnl Copyright (c) 2019 Triad National Security, LLC. All rights
dnl reserved.
dnl
dnl $COPYRIGHT$
dnl
dnl Additional copyrights may follow
dnl
dnl $HEADER$
dnl
dnl we only want one :)
m4_define(MCA_opal_threads_CONFIGURE_MODE, STOP_AT_FIRST)
AC_DEFUN([MCA_opal_threads_CONFIG],[
#
# Arguments: none
#
# Dependencies: None
#
# Modifies:
# none - see called tests
#
# configure threads
#
#
# First see what kind of threads we are going to use
#
AC_ARG_WITH([threads],
[AC_HELP_STRING([--with-threads=TYPE],
[Specify thread TYPE to use. default:pthreads. Other options are qthreads and argobots.])])
#
# Configure components
#
MCA_CONFIGURE_FRAMEWORK($1, $2, 1)
AS_IF([test x"$opal_thread_type_found" = x""],
[AC_MSG_ERROR([Did not find a suitable threads component])])
AC_MSG_RESULT([Found thread type $opal_thread_type_found])
OPAL_SUMMARY_ADD([[Miscellaneous]],[[Threading Package]],[], [$opal_thread_type_found])
])dnl

Просмотреть файл

@ -15,6 +15,7 @@
* reserved.
* Copyright (c) 2007 Voltaire. All rights reserved.
* Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
@ -23,13 +24,11 @@
* $HEADER$
*/
#ifndef OPAL_MUTEX_H
#define OPAL_MUTEX_H 1
#ifndef OPAL_MCA_THREADS_MUTEX_H
#define OPAL_MCA_THREADS_MUTEX_H
#include "opal_config.h"
#include "opal/threads/thread_usage.h"
BEGIN_C_DECLS
/**
@ -43,9 +42,16 @@ BEGIN_C_DECLS
/**
* Opaque mutex object
*/
typedef struct opal_mutex_t opal_mutex_t;
typedef struct opal_mutex_t opal_recursive_mutex_t;
#include MCA_threads_mutex_base_include_HEADER
OBJ_CLASS_DECLARATION(opal_mutex_t);
OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);
/**
* Try to acquire a mutex.
*
@ -95,11 +101,6 @@ static inline void opal_mutex_atomic_lock(opal_mutex_t *mutex);
*/
static inline void opal_mutex_atomic_unlock(opal_mutex_t *mutex);
END_C_DECLS
#include "mutex_unix.h"
BEGIN_C_DECLS
/**
* Lock a mutex if opal_using_threads() says that multiple threads may
@ -114,11 +115,11 @@ BEGIN_C_DECLS
* If there is no possibility that multiple threads are running in the
* process, return immediately.
*/
#define OPAL_THREAD_LOCK(mutex) \
do { \
if (OPAL_UNLIKELY(opal_using_threads())) { \
opal_mutex_lock(mutex); \
} \
#define OPAL_THREAD_LOCK(mutex) \
do { \
if (OPAL_UNLIKELY(opal_using_threads())) { \
opal_mutex_lock(mutex); \
} \
} while (0)
@ -137,7 +138,7 @@ BEGIN_C_DECLS
*
* Returns 0 if mutex was locked, non-zero otherwise.
*/
#define OPAL_THREAD_TRYLOCK(mutex) \
#define OPAL_THREAD_TRYLOCK(mutex) \
(OPAL_UNLIKELY(opal_using_threads()) ? opal_mutex_trylock(mutex) : 0)
/**
@ -153,11 +154,11 @@ BEGIN_C_DECLS
* If there is no possibility that multiple threads are running in the
* process, return immediately without modifying the mutex.
*/
#define OPAL_THREAD_UNLOCK(mutex) \
do { \
if (OPAL_UNLIKELY(opal_using_threads())) { \
opal_mutex_unlock(mutex); \
} \
#define OPAL_THREAD_UNLOCK(mutex) \
do { \
if (OPAL_UNLIKELY(opal_using_threads())) { \
opal_mutex_unlock(mutex); \
} \
} while (0)
@ -176,17 +177,17 @@ BEGIN_C_DECLS
* If there is no possibility that multiple threads are running in the
* process, invoke the action without acquiring the lock.
*/
#define OPAL_THREAD_SCOPED_LOCK(mutex, action) \
do { \
if(OPAL_UNLIKELY(opal_using_threads())) { \
opal_mutex_lock(mutex); \
action; \
opal_mutex_unlock(mutex); \
} else { \
action; \
} \
#define OPAL_THREAD_SCOPED_LOCK(mutex, action) \
do { \
if (OPAL_UNLIKELY(opal_using_threads())) { \
opal_mutex_lock(mutex); \
action; \
opal_mutex_unlock(mutex); \
} else { \
action; \
} \
} while (0)
END_C_DECLS
#endif /* OPAL_MUTEX_H */
#endif /* OPAL_MCA_THREADS_MUTEX_H */

32
opal/mca/threads/pthreads/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,32 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
noinst_LTLIBRARIES = libmca_threads_pthreads.la
libmca_threads_pthreads_la_SOURCES = \
threads_pthreads_component.c \
threads_pthreads_condition.c \
threads_pthreads_module.c \
threads_pthreads_mutex.c \
threads_pthreads_mutex.h \
threads_pthreads_threads.h \
threads_pthreads_tsd.h \
threads_pthreads_wait_sync.c \
threads_pthreads_wait_sync.h

Просмотреть файл

@ -1,28 +1,27 @@
dnl
dnl Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
dnl University Research and Technology
dnl Corporation. All rights reserved.
dnl Copyright (c) 2004-2005 The University of Tennessee and The University
dnl of Tennessee Research Foundation. All rights
dnl reserved.
dnl Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
dnl University of Stuttgart. All rights reserved.
dnl Copyright (c) 2004-2005 The Regents of the University of California.
dnl All rights reserved.
dnl Copyright (c) 2012 Cisco Systems, Inc. All rights reserved.
dnl Copyright (c) 2014 Intel, Inc. All rights reserved.
dnl Copyright (c) 2014-2016 Research Organization for Information Science
dnl and Technology (RIST). All rights reserved.
dnl $COPYRIGHT$
dnl
dnl Additional copyrights may follow
dnl
dnl $HEADER$
dnl
dnl OPAL_CONFIG_POSIX_THREADS()
dnl
dnl Configure posix threads, setting the following variables (but
dnl not calling AC_SUBST on them).
# -*- shell-script -*-
#
# Copyright (c) 2004-2006 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2008-2020 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2015 Research Organization for Information Science
# and Technology (RIST). All rights reserved.
# Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
# Copyright (c) 2019 Triad National Security, LLC. All rights
# reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
# ********************************************************************
#
@ -31,6 +30,101 @@ dnl not calling AC_SUBST on them).
# ********************************************************************
AC_DEFUN([OPAL_CHECK_PTHREAD_PIDS],[
#
# Arguments: none
#
# Dependencies: None
#
# Sets:
# OPAL_THREADS_HAVE_DIFFERENT_PIDS (variable)
#
# Test for Linux-like threads in the system. OPAL no longer supports
# systems with different PIDs for threads in the same process, so error
# out if we detect that case.
#
AC_MSG_CHECKING([if threads have different pids (pthreads on linux)])
OPAL_VAR_SCOPE_PUSH([CFLAGS_save CPPFLAGS_save LDFLAGS_save LIBS_save MSG])
CFLAGS_save="$CFLAGS"
CFLAGS="$CFLAGS $THREAD_CFLAGS"
CPPFLAGS_save="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $THREAD_CPPFLAGS"
LDFLAGS_save="$LDFLAGS"
LDFLAGS="$LDFLAGS $THREAD_LDFLAGS"
LIBS_save="$LIBS"
LIBS="$LIBS $THREAD_LIBS"
AC_RUN_IFELSE([AC_LANG_SOURCE([#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
void *checkpid(void *arg);
int main() {
pthread_t thr;
int pid, *retval;
pid = getpid();
pthread_create(&thr, NULL, checkpid, &pid);
pthread_join(thr, (void **) &retval);
exit(*retval);
}
static int ret;
void *checkpid(void *arg) {
int ppid = *((int *) arg);
if (ppid == getpid())
ret = 0;
else
ret = 1;
pthread_exit((void *) &ret);
}])],
[MSG=no OPAL_THREADS_HAVE_DIFFERENT_PIDS=0],
[MSG=yes OPAL_THREADS_HAVE_DIFFERENT_PIDS=1],
[
# If we're cross compiling, we can't do another AC_* function here because
# it we haven't displayed the result from the last one yet. So defer
# another test until below.
OPAL_THREADS_HAVE_DIFFERENT_PIDS=
MSG="cross compiling (need another test)"])
CFLAGS="$CFLAGS_save"
CPPFLAGS="$CPPFLAGS_save"
LDFLAGS="$LDFLAGS_save"
LIBS="$LIBS_save"
AC_MSG_RESULT([$MSG])
AS_IF([test "x$OPAL_THREADS_HAVE_DIFFERENT_PIDS" = "x"],
[ # If we are cross-compiling, look for the symbol
# __linuxthreads_create_event, which seems to only exist in the
# Linux Threads-based pthreads implementation (i.e., the one
# that has different PIDs for each thread). We *could* switch
# on $host here and only test *linux* hosts, but this test is
# pretty unique, so why bother? Note that AC_CHECK_FUNC works
# properly in cross-compiling environments in recent-enough
# versions of Autoconf (which is one of the reasons we mandate
# recent versions in autogen!).
AC_CHECK_FUNC([__linuxthreads_create_event],
[OPAL_THREADS_HAVE_DIFFERENT_PIDS=1])])
AS_IF([test "$OPAL_THREADS_HAVE_DIFFERENT_PIDS" = "1"],
[AC_MSG_WARN([This version of Open MPI only supports environments where])
AC_MSG_WARN([threads have the same PID. Please use an older version of])
AC_MSG_WARN([Open MPI if you need support on systems with different])
AC_MSG_WARN([PIDs for threads in the same process. Open MPI 1.4.x])
AC_MSG_WARN([supports such systems, as does at least some versions the])
AC_MSG_WARN([Open MPI 1.5.x series.])
AC_MSG_ERROR([Cannot continue])
])
#
# if pthreads is not available, then the system does not have an insane threads
# model
#
OPAL_VAR_SCOPE_POP
])dnl
AC_DEFUN([OPAL_INTL_PTHREAD_TRY_LINK], [
# BEGIN: OPAL_INTL_PTHREAD_TRY_LINK
#
@ -78,6 +172,8 @@ AC_DEFUN([OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN], [
# Make sure that we can run a small application in Fortran, with
# pthreads living in a C object file
OPAL_VAR_SCOPE_PUSH([HAPPY opal_conftest_h])
# Fortran module
cat > conftestf.f <<EOF
program fpthread
@ -105,7 +201,12 @@ pthread_t me, newthread;
void cleanup_routine(void *foo);
void *thread_main(void *foo);
void pthreadtest_f(void);
void pthreadtest(void);
void pthreadtest_(void);
void pthreadtest__(void);
void PTHREADTEST(void);
void cleanup_routine(void *foo) { i = 4; }
void *thread_main(void *foo) { i = 2; return (void*) &i; }
@ -163,8 +264,9 @@ else
$2
fi
unset HAPPY opal_conftest_h
rm -rf conftest*
OPAL_VAR_SCOPE_POP
# END: OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN
])dnl
@ -281,11 +383,11 @@ if test "$opal_pthread_c_success" = "0"; then
opal_pthread_c_success=0)
AC_LANG_POP(C)
if test "$opal_pthread_c_success" = "1"; then
PTHREAD_CFLAGS="$pf"
TPKG_CFLAGS="$pf"
AC_MSG_RESULT([yes])
break
else
PTHREAD_CFLAGS=
TPKG_CFLAGS=
CFLAGS="$orig_CFLAGS"
AC_MSG_RESULT([no])
fi
@ -307,11 +409,11 @@ if test "$opal_pthread_cxx_success" = "0"; then
opal_pthread_cxx_success=0)
AC_LANG_POP(C++)
if test "$opal_pthread_cxx_success" = "1"; then
PTHREAD_CXXFLAGS="$pf"
TPKG_CXXFLAGS="$pf"
AC_MSG_RESULT([yes])
break
else
PTHREAD_CXXFLAGS=
TPKG_CXXFLAGS=
CXXFLAGS="$orig_CXXFLAGS"
AC_MSG_RESULT([no])
fi
@ -335,11 +437,11 @@ if test "$opal_pthread_fortran_success" = "0" && \
opal_pthread_fortran_success=0)
AC_LANG_POP(C)
if test "$opal_pthread_fortran_success" = "1"; then
PTHREAD_FCFLAGS="$pf"
TPKG_FCFLAGS="$pf"
AC_MSG_RESULT([yes])
break
else
PTHREAD_FCFLAGS=
TPKG_FCFLAGS=
FCFLAGS="$orig_FCFLAGS"
AC_MSG_RESULT([no])
fi
@ -364,6 +466,7 @@ AC_DEFUN([OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS],[
# Put -mt before -mthreads because HP-UX aCC will properly compile
# with -mthreads (reading as -mt), but emit a warning about unknown
# flags hreads. Stupid compilers.
OPAL_VAR_SCOPE_PUSH([pflags])
case "${host_cpu}-${host_os}" in
*solaris*)
@ -387,6 +490,7 @@ AC_PROVIDE_IFELSE([AC_PROG_FC],
[OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS_FC],
[opal_pthread_fortran_success=1])
OPAL_VAR_SCOPE_POP
# End: OPAL_INTL_POSIX_THREADS_SPECIAL_FLAGS
])dnl
@ -406,14 +510,14 @@ if test "$opal_pthread_c_success" = "0"; then
case "${host_cpu}-${host-_os}" in
*-aix* | *-freebsd*)
if test "`echo $CPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then
PTHREAD_CPPFLAGS="-D_THREAD_SAFE"
CPPFLAGS="$CPPFLAGS $PTHREAD_CPPFLAGS"
TPKG_CPPFLAGS="-D_THREAD_SAFE"
CPPFLAGS="$CPPFLAGS $TPKG_CPPFLAGS"
fi
;;
*)
if test "`echo $CPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then
PTHREAD_CPPFLAGS="-D_REENTRANT"
CPPFLAGS="$CPPFLAGS $PTHREAD_CPPFLAGS"
TPKG_CPPFLAGS="-D_REENTRANT"
CPPFLAGS="$CPPFLAGS $TPKG_CPPFLAGS"
fi
;;
esac
@ -423,10 +527,10 @@ if test "$opal_pthread_c_success" = "0"; then
opal_pthread_c_success=0)
AC_LANG_POP(C)
if test "$opal_pthread_c_success" = "1"; then
PTHREAD_LIBS="$pl"
TPKG_LIBS="$pl"
AC_MSG_RESULT([yes])
else
PTHREAD_CPPFLAGS=
TPKG_CPPFLAGS=
CPPFLAGS="$orig_CPPFLAGS"
LIBS="$orig_LIBS"
AC_MSG_RESULT([no])
@ -441,23 +545,23 @@ AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS_CXX],[
# C++ compiler
#
if test "$opal_pthread_cxx_success" = "0"; then
if test ! "$opal_pthread_c_success" = "0" && test ! "$PTHREAD_LIBS" = "" ; then
AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $PTHREAD_LIBS])
if test ! "$opal_pthread_c_success" = "0" && test ! "$TPKG_LIBS" = "" ; then
AC_MSG_CHECKING([if C++ compiler and POSIX threads work with $TPKG_LIBS])
case "${host_cpu}-${host-_os}" in
*-aix* | *-freebsd*)
if test "`echo $CXXCPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then
PTHREAD_CXXCPPFLAGS="-D_THREAD_SAFE"
CXXCPPFLAGS="$CXXCPPFLAGS $PTHREAD_CXXCPPFLAGS"
TPKG_CXXCPPFLAGS="-D_THREAD_SAFE"
CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS"
fi
;;
*)
if test "`echo $CXXCPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then
PTHREAD_CXXCPPFLAGS="-D_REENTRANT"
CXXCPPFLAGS="$CXXCPPFLAGS $PTHREAD_CXXCPPFLAGS"
TPKG_CXXCPPFLAGS="-D_REENTRANT"
CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS"
fi
;;
esac
LIBS="$orig_LIBS $PTHREAD_LIBS"
LIBS="$orig_LIBS $TPKG_LIBS"
AC_LANG_PUSH(C++)
OPAL_INTL_PTHREAD_TRY_LINK(opal_pthread_cxx_success=1,
opal_pthread_cxx_success=0)
@ -476,14 +580,14 @@ if test "$opal_pthread_cxx_success" = "0"; then
case "${host_cpu}-${host-_os}" in
*-aix* | *-freebsd*)
if test "`echo $CXXCPPFLAGS | $GREP 'D_THREAD_SAFE'`" = ""; then
PTHREAD_CXXCPPFLAGS="-D_THREAD_SAFE"
CXXCPPFLAGS="$CXXCPPFLAGS $PTHREAD_CXXCPPFLAGS"
TPKG_CXXCPPFLAGS="-D_THREAD_SAFE"
CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS"
fi
;;
*)
if test "`echo $CXXCPPFLAGS | $GREP 'D_REENTRANT'`" = ""; then
PTHREAD_CXXCPPFLAGS="-D_REENTRANT"
CXXCPPFLAGS="$CXXCPPFLAGS $PTHREAD_CXXCPPFLAGS"
TPKG_CXXCPPFLAGS="-D_REENTRANT"
CXXCPPFLAGS="$CXXCPPFLAGS $TPKG_CXXCPPFLAGS"
fi
;;
esac
@ -493,10 +597,10 @@ if test "$opal_pthread_cxx_success" = "0"; then
opal_pthread_cxx_success=0)
AC_LANG_POP(C++)
if test "$opal_pthread_cxx_success" = "1"; then
PTHREAD_LIBS="$pl"
TPKG_LIBS="$pl"
AC_MSG_RESULT([yes])
else
PTHREAD_CXXCPPFLAGS=
TPKG_CXXCPPFLAGS=
CXXCPPFLAGS="$orig_CXXCPPFLAGS"
LIBS="$orig_LIBS"
AC_MSG_RESULT([no])
@ -511,12 +615,12 @@ AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS_FC],[
#
# Fortran compiler
#
if test "$opal_pthread_fortran_success" = "0" && \
if test $opal_pthread_fortran_success -eq 0 && \
test "$OMPI_TRY_FORTRAN_BINDINGS" -gt "$OMPI_FORTRAN_NO_BINDINGS" && \
test $ompi_fortran_happy -eq 1; then
if test ! "$opal_pthread_c_success" = "0" && test ! "$PTHREAD_LIBS" = "" ; then
AC_MSG_CHECKING([if Fortran compiler and POSIX threads work with $PTHREAD_LIBS])
LIBS="$orig_LIBS $PTHREAD_LIBS"
if test $opal_pthread_c_success -ne 0 && test ! "$TPKG_LIBS" = "" ; then
AC_MSG_CHECKING([if Fortran compiler and POSIX threads work with $TPKG_LIBS])
LIBS="$orig_LIBS $TPKG_LIBS"
AC_LANG_PUSH(C)
OPAL_INTL_PTHREAD_TRY_LINK_FORTRAN(opal_pthread_fortran_success=1,
opal_pthread_fortran_success=0)
@ -537,7 +641,7 @@ if test "$opal_pthread_fortran_success" = "0" && \
opal_pthread_fortran_success=0)
AC_LANG_POP(C)
if test "$opal_pthread_fortran_success" = "1"; then
PTHREAD_LIBS="$pl"
TPKG_LIBS="$pl"
AC_MSG_RESULT([yes])
break
else
@ -561,6 +665,7 @@ AC_DEFUN([OPAL_INTL_POSIX_THREADS_LIBS],[
# libpthreads: AIX - must check before libpthread
# liblthread: LinuxThreads on FreeBSD
# libpthread: The usual place (like we can define usual!)
OPAL_VAR_SCOPE_PUSH([plibs])
plibs="-lpthreads -llthread -lpthread"
# Only run C++ and Fortran if those compilers already configured
@ -576,6 +681,7 @@ AC_PROVIDE_IFELSE([AC_PROG_FC],
[OPAL_INTL_POSIX_THREADS_LIBS_FC],
[opal_pthread_fortran_success=1])
OPAL_VAR_SCOPE_POP
# End: OPAL_INTL_POSIX_THREADS_LIBS]
)dnl
@ -586,6 +692,7 @@ AC_PROVIDE_IFELSE([AC_PROG_FC],
#
#********************************************************************
AC_DEFUN([OPAL_CONFIG_POSIX_THREADS],[
OPAL_VAR_SCOPE_PUSH([opal_pthreads_result defval opal_pthread_c_success opal_pthread_fortran_success opal_pthread_cxx_success orig_CFLAGS orig_FCFLAGS orig_CXXFLAGS orig_CPPFLAGS orig_CXXCPPFLAGS orig_LDFLAGS orig_LIBS])
AC_REQUIRE([AC_PROG_GREP])
opal_pthread_c_success=0
@ -600,13 +707,13 @@ orig_CXXCPPFLAGS="$CXXCPPFLAGS"
orig_LDFLAGS="$LDFLAGS"
orig_LIBS="$LIBS"
PTHREAD_CFLAGS=
PTHREAD_FCFLAGS=
PTHREAD_CXXFLAGS=
PTHREAD_CPPFLAGS=
PTHREAD_CXXCPPFLAGS=
PTHREAD_LDFLAGS=
PTHREAD_LIBS=
TPKG_CFLAGS=
TPKG_FCFLAGS=
TPKG_CXXFLAGS=
TPKG_CPPFLAGS=
TPKG_CXXCPPFLAGS=
TPKG_LDFLAGS=
TPKG_LIBS=
# Try with the basics, mam.
OPAL_INTL_POSIX_THREADS_PLAIN
@ -632,8 +739,8 @@ AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[#include <pthread.h>]],
[[pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_ERRORCHECK_NP);]])],
[result="yes" defval=1], [result="no" defval=0])
AC_MSG_RESULT([$result])
[opal_pthreads_result="yes" defval=1], [opal_pthreads_result="no" defval=0])
AC_MSG_RESULT([$opal_pthreads_result])
AC_DEFINE_UNQUOTED([OPAL_HAVE_PTHREAD_MUTEX_ERRORCHECK_NP], [$defval],
[If PTHREADS implementation supports PTHREAD_MUTEX_ERRORCHECK_NP])
@ -643,8 +750,8 @@ AC_LINK_IFELSE(
[AC_LANG_PROGRAM(
[[#include <pthread.h>]],
[[pthread_mutexattr_settype(NULL, PTHREAD_MUTEX_ERRORCHECK);]])],
[result="yes" defval=1], [result="no" defval=0])
AC_MSG_RESULT([$result])
[opal_pthreads_result="yes" defval=1], [opal_pthreads_result="no" defval=0])
AC_MSG_RESULT([$opal_pthreads_result])
AC_DEFINE_UNQUOTED([OPAL_HAVE_PTHREAD_MUTEX_ERRORCHECK], [$defval],
[If PTHREADS implementation supports PTHREAD_MUTEX_ERRORCHECK])
@ -656,21 +763,91 @@ CXXCPPFLAGS="$orig_CXXCPPFLAGS"
LDFLAGS="$orig_LDFLAGS"
LIBS="$orig_LIBS"
THREAD_CFLAGS="$TPKG_CFLAGS"
THREAD_FCFLAGS="$TPKG_FCFLAGS"
THREAD_CXXFLAGS="$TPKG_CXXFLAGS"
THREAD_CPPFLAGS="$TPKG_CPPFLAGS"
THREAD_CXXCPPFLAGS="$TPKG_CXXCPPFLAGS"
THREAD_LDFLAGS="$TPKG_LDFLAGS"
THREAD_LIBS="$TPKG_LIBS"
OPAL_CHECK_PTHREAD_PIDS
if test "$OMPI_TRY_FORTRAN_BINDINGS" = "$OMPI_FORTRAN_NO_BINDINGS" || \
test $ompi_fortran_happy -ne 1; then
opal_pthread_fortran_success=1
opal_pthread_fortran_success=1
fi
if test "$opal_pthread_c_success" = "1" && \
test "$opal_pthread_cxx_success" = "1" && \
test "$opal_pthread_fortran_success" = "1"; then
internal_useless=1
$1
AC_MSG_CHECKING([if POSIX threads work])
if test $opal_pthread_c_success -eq 1 && \
test $opal_pthread_cxx_success -eq 1 && \
test $opal_pthread_fortran_success -eq 1; then
AC_MSG_RESULT([yes])
$1
else
internal_useless=1
$2
AC_MSG_RESULT([no])
$2
fi
unset opal_pthread_c_success opal_pthread_fortran_success opal_pthread_cxx_success
unset internal_useless
OPAL_VAR_SCOPE_POP
])dnl
AC_DEFUN([MCA_opal_threads_pthreads_PRIORITY], [30])
AC_DEFUN([MCA_opal_threads_pthreads_COMPILE_MODE], [
AC_MSG_CHECKING([for MCA component $2:$3 compile mode])
$4="static"
AC_MSG_RESULT([$$4])
])
# If component was selected, $1 will be 1 and we should set the base header
AC_DEFUN([MCA_opal_threads_pthreads_POST_CONFIG],[
AS_IF([test "$1" = "1"],
[opal_thread_type_found="pthreads"
AC_DEFINE_UNQUOTED([MCA_threads_base_include_HEADER],
["opal/mca/threads/pthreads/threads_pthreads_threads.h"],
[Header to include for threads implementation])
AC_DEFINE_UNQUOTED([MCA_threads_mutex_base_include_HEADER],
["opal/mca/threads/pthreads/threads_pthreads_mutex.h"],
[Header to include for mutex implementation])
AC_DEFINE_UNQUOTED([MCA_threads_tsd_base_include_HEADER],
["opal/mca/threads/pthreads/threads_pthreads_tsd.h"],
[Header to include for tsd implementation])
AC_DEFINE_UNQUOTED([MCA_threads_wait_sync_base_include_HEADER],
["opal/mca/threads/pthreads/threads_pthreads_wait_sync.h"],
[Header to include for wait_sync implementation])
THREAD_CFLAGS="$TPKG_CFLAGS"
THREAD_FCFLAGS="$TPKG_FCFLAGS"
THREAD_CXXFLAGS="$TPKG_CXXFLAGS"
THREAD_CPPFLAGS="$TPKG_CPPFLAGS"
THREAD_CXXCPPFLAGS="$TPKG_CXXCPPFLAGS"
THREAD_LDFLAGS="$TPKG_LDFLAGS"
THREAD_LIBS="$TPKG_LIBS"
AC_SUBST(THREAD_CFLAGS)
AC_SUBST(THREAD_FCFLAGS)
AC_SUBST(THREAD_CXXFLAGS)
AC_SUBST(THREAD_CPPFLAGS)
AC_SUBST(THREAD_LDFLAGS)
AC_SUBST(THREAD_LIBS)
])
])dnl
# MCA_threads_pthreads_CONFIG(action-if-can-compile,
# [action-if-cant-compile])
# ------------------------------------------------
AC_DEFUN([MCA_opal_threads_pthreads_CONFIG],[
AC_CONFIG_FILES([opal/mca/threads/pthreads/Makefile])
OPAL_VAR_SCOPE_PUSH([posix_thread_works])
AS_IF([test -z "$with_threads" || test "$with_threads" = "pthreads" || test "$with_threads" = "yes"],
[OPAL_CONFIG_POSIX_THREADS([posix_threads_works=1],[posix_threads_works=0])],
[posix_threads_works=0])
AS_IF([test $posix_threads_works -eq 1],
[$1],
[$2])
OPAL_VAR_SCOPE_POP
])

7
opal/mca/threads/pthreads/owner.txt Обычный файл
Просмотреть файл

@ -0,0 +1,7 @@
#
# owner/status file
# owner: institution that is responsible for this package
# status: e.g. active, maintenance, unmaintained
#
owner: SNL
status: active

Просмотреть файл

@ -0,0 +1,54 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2014 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2015 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include "opal/mca/threads/thread.h"
#include "opal/mca/threads/threads.h"
#include "opal/constants.h"
static int opal_threads_pthreads_open(void);
const opal_threads_base_component_1_0_0_t mca_threads_pthreads_component = {
/* First, the mca_component_t struct containing meta information
* about the component itself */
.threadsc_version = {
OPAL_THREADS_BASE_VERSION_1_0_0,
/* Component name and version */
.mca_component_name = "pthreads",
MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION,
OPAL_RELEASE_VERSION),
.mca_open_component = opal_threads_pthreads_open,
},
.threadsc_data = {
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
},
};
int opal_threads_pthreads_open(void)
{
return OPAL_SUCCESS;
}

Просмотреть файл

@ -1,3 +1,4 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
@ -9,6 +10,8 @@
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -18,7 +21,7 @@
#include "opal_config.h"
#include "opal/threads/condition.h"
#include "opal/mca/threads/condition.h"
static void opal_condition_construct(opal_condition_t *c)
@ -27,7 +30,6 @@ static void opal_condition_construct(opal_condition_t *c)
c->c_signaled = 0;
}
static void opal_condition_destruct(opal_condition_t *c)
{
}

Просмотреть файл

@ -1,17 +1,21 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2010 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2015-2017 Research Organization for Information Science
* Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -19,68 +23,36 @@
* $HEADER$
*/
#include "opal_config.h"
#include <unistd.h>
#include "opal/threads/threads.h"
#include "opal/threads/tsd.h"
#include "opal/constants.h"
bool opal_debug_threads = false;
static void opal_thread_construct(opal_thread_t *t);
static pthread_t opal_main_thread;
#include "opal/util/sys_limits.h"
#include "opal/util/output.h"
#include "opal/prefetch.h"
#include "opal/mca/threads/threads.h"
#include "opal/mca/threads/tsd.h"
struct opal_tsd_key_value {
opal_tsd_key_t key;
opal_tsd_destructor_t destructor;
};
static struct opal_tsd_key_value *opal_tsd_key_values = NULL;
static pthread_t opal_main_thread;
struct opal_tsd_key_value *opal_tsd_key_values = NULL;
static int opal_tsd_key_values_count = 0;
OBJ_CLASS_INSTANCE(opal_thread_t,
opal_object_t,
opal_thread_construct, NULL);
/*
* Constructor
*/
static void opal_thread_construct(opal_thread_t *t)
{
t->t_run = 0;
t->t_handle = (pthread_t) -1;
t->t_handle = (pthread_t)-1;
}
int opal_thread_start(opal_thread_t *t)
{
int rc;
if (OPAL_ENABLE_DEBUG) {
if (NULL == t->t_run || t->t_handle != (pthread_t) -1) {
return OPAL_ERR_BAD_PARAM;
}
}
rc = pthread_create(&t->t_handle, NULL, (void*(*)(void*)) t->t_run, t);
return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR;
}
int opal_thread_join(opal_thread_t *t, void **thr_return)
{
int rc = pthread_join(t->t_handle, thr_return);
t->t_handle = (pthread_t) -1;
return (rc == 0) ? OPAL_SUCCESS : OPAL_ERROR;
}
bool opal_thread_self_compare(opal_thread_t *t)
{
return t->t_handle == pthread_self();
}
OBJ_CLASS_INSTANCE(opal_thread_t,
opal_object_t,
opal_thread_construct, NULL);
opal_thread_t *opal_thread_get_self(void)
@ -90,31 +62,62 @@ opal_thread_t *opal_thread_get_self(void)
return t;
}
void opal_thread_kill(opal_thread_t *t, int sig)
bool opal_thread_self_compare(opal_thread_t *t)
{
pthread_kill(t->t_handle, sig);
return pthread_self() == t->t_handle;
}
int opal_tsd_key_create(opal_tsd_key_t *key,
opal_tsd_destructor_t destructor)
int opal_thread_join(opal_thread_t *t, void **thr_return)
{
int rc = pthread_join(t->t_handle, thr_return);
t->t_handle = (pthread_t)-1;
return 0 == rc ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
}
void opal_thread_set_main(void)
{
opal_main_thread = pthread_self();
}
int opal_thread_start(opal_thread_t *t)
{
int rc;
if (OPAL_ENABLE_DEBUG) {
if (NULL == t->t_run || (pthread_t)-1 != t->t_handle) {
return OPAL_ERR_BAD_PARAM;
}
}
rc = pthread_create(&t->t_handle, NULL, (void *(*)(void *))t->t_run, t);
return 0 == rc ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
}
OBJ_CLASS_DECLARATION(opal_thread_t);
int opal_tsd_key_create(opal_tsd_key_t *key, opal_tsd_destructor_t destructor)
{
int rc;
rc = pthread_key_create(key, destructor);
if ((0 == rc) && (pthread_self() == opal_main_thread)) {
opal_tsd_key_values = (struct opal_tsd_key_value *)realloc(opal_tsd_key_values, (opal_tsd_key_values_count+1) * sizeof(struct opal_tsd_key_value));
opal_tsd_key_values = (struct opal_tsd_key_value *)
realloc(opal_tsd_key_values, (opal_tsd_key_values_count + 1) *
sizeof(struct opal_tsd_key_value));
opal_tsd_key_values[opal_tsd_key_values_count].key = *key;
opal_tsd_key_values[opal_tsd_key_values_count].destructor = destructor;
opal_tsd_key_values_count ++;
opal_tsd_key_values_count++;
}
return rc;
return 0 == rc ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
}
int opal_tsd_keys_destruct()
int opal_tsd_keys_destruct(void)
{
int i;
void * ptr;
for (i=0; i<opal_tsd_key_values_count; i++) {
if(OPAL_SUCCESS == opal_tsd_getspecific(opal_tsd_key_values[i].key, &ptr)) {
void *ptr;
for (i = 0; i < opal_tsd_key_values_count; i++) {
if (OPAL_SUCCESS ==
opal_tsd_getspecific(opal_tsd_key_values[i].key, &ptr)) {
if (NULL != opal_tsd_key_values[i].destructor) {
opal_tsd_key_values[i].destructor(ptr);
opal_tsd_setspecific(opal_tsd_key_values[i].key, NULL);
@ -128,6 +131,7 @@ int opal_tsd_keys_destruct()
return OPAL_SUCCESS;
}
void opal_thread_set_main() {
opal_main_thread = pthread_self();
void opal_event_use_threads(void)
{
evthread_use_pthreads();
}

Просмотреть файл

@ -0,0 +1,133 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "opal_config.h"
#include <errno.h>
#include <pthread.h>
#include "opal/mca/threads/mutex.h"
#include "opal/mca/threads/pthreads/threads_pthreads_mutex.h"
#include "opal/constants.h"
/*
* Wait and see if some upper layer wants to use threads, if support
* exists.
*/
bool opal_uses_threads = false;
struct opal_pthread_mutex_t {
opal_object_t super;
pthread_mutex_t m_lock_pthread;
opal_atomic_lock_t m_lock_atomic;
#if OPAL_ENABLE_DEBUG
int m_lock_debug;
const char *m_lock_file;
int m_lock_line;
#endif
};
typedef struct opal_pthread_mutex_t opal_pthread_mutex_t;
typedef struct opal_pthread_mutex_t opal_pthread_recursive_mutex_t;
static void mca_threads_pthreads_mutex_constructor(opal_mutex_t *p_mutex)
{
pthread_mutex_init(&p_mutex->m_lock_pthread, NULL);
#if OPAL_ENABLE_DEBUG
p_mutex->m_lock_debug = 0;
p_mutex->m_lock_file = NULL;
p_mutex->m_lock_line = 0;
#endif
opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0);
}
static void mca_threads_pthreads_mutex_destructor(opal_mutex_t *p_mutex)
{
pthread_mutex_destroy(&p_mutex->m_lock_pthread);
}
static void mca_threads_pthreads_recursive_mutex_constructor
(opal_recursive_mutex_t *p_mutex)
{
pthread_mutexattr_t mutex_attr;
pthread_mutexattr_init(&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&p_mutex->m_lock_pthread, &mutex_attr);
pthread_mutexattr_destroy(&mutex_attr);
#if OPAL_ENABLE_DEBUG
p_mutex->m_lock_debug = 0;
p_mutex->m_lock_file = NULL;
p_mutex->m_lock_line = 0;
#endif
opal_atomic_lock_init(&p_mutex->m_lock_atomic, 0);
}
static void mca_threads_pthreads_recursive_mutex_destructor
(opal_recursive_mutex_t *p_mutex)
{
pthread_mutex_destroy(&p_mutex->m_lock_pthread);
}
OBJ_CLASS_INSTANCE(opal_mutex_t,
opal_object_t,
mca_threads_pthreads_mutex_constructor,
mca_threads_pthreads_mutex_destructor);
OBJ_CLASS_INSTANCE(opal_recursive_mutex_t,
opal_object_t,
mca_threads_pthreads_recursive_mutex_constructor,
mca_threads_pthreads_recursive_mutex_destructor);
int opal_cond_init(opal_cond_t *cond)
{
int ret = pthread_cond_init(cond, NULL);
return 0 == ret ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
}
int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock)
{
int ret = pthread_cond_wait(cond, &lock->m_lock_pthread);
return 0 == ret ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
}
int opal_cond_broadcast(opal_cond_t *cond)
{
int ret = pthread_cond_broadcast(cond);
return 0 == ret ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
}
int opal_cond_signal(opal_cond_t *cond)
{
int ret = pthread_cond_signal(cond);
return 0 == ret ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
}
int opal_cond_destroy(opal_cond_t *cond)
{
int ret = pthread_cond_destroy(cond);
return 0 == ret ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
}

Просмотреть файл

@ -14,6 +14,10 @@
* reserved.
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
* Copyright (c) 2020 Triad National Security, LLC. All rights
* reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -21,8 +25,8 @@
* $HEADER$
*/
#ifndef OPAL_MUTEX_UNIX_H
#define OPAL_MUTEX_UNIX_H 1
#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H
#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H
/**
* @file:
@ -43,6 +47,7 @@
#include "opal/class/opal_object.h"
#include "opal/sys/atomic.h"
#include "opal/util/output.h"
BEGIN_C_DECLS
@ -63,9 +68,11 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_mutex_t);
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);
#if defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP)
#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER \
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
#elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER PTHREAD_RECURSIVE_MUTEX_INITIALIZER
#define OPAL_PTHREAD_RECURSIVE_MUTEX_INITIALIZER \
PTHREAD_RECURSIVE_MUTEX_INITIALIZER
#endif
#if OPAL_ENABLE_DEBUG
@ -118,27 +125,23 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_recursive_mutex_t);
static inline int opal_mutex_trylock(opal_mutex_t *m)
{
#if OPAL_ENABLE_DEBUG
int ret = pthread_mutex_trylock(&m->m_lock_pthread);
if (ret == EDEADLK) {
errno = ret;
perror("opal_mutex_trylock()");
abort();
}
return ret;
#else
return pthread_mutex_trylock(&m->m_lock_pthread);
if (EDEADLK == ret) {
#if OPAL_ENABLE_DEBUG
opal_output(0, "opal_mutex_trylock() %d",ret);
#endif
return 1;
}
return 0 == ret ? 0 : 1;
}
static inline void opal_mutex_lock(opal_mutex_t *m)
{
#if OPAL_ENABLE_DEBUG
int ret = pthread_mutex_lock(&m->m_lock_pthread);
if (ret == EDEADLK) {
if (EDEADLK == ret) {
errno = ret;
perror("opal_mutex_lock()");
abort();
opal_output(0, "opal_mutex_lock() %d", ret);
}
#else
pthread_mutex_lock(&m->m_lock_pthread);
@ -149,10 +152,9 @@ static inline void opal_mutex_unlock(opal_mutex_t *m)
{
#if OPAL_ENABLE_DEBUG
int ret = pthread_mutex_unlock(&m->m_lock_pthread);
if (ret == EPERM) {
if (EPERM == ret) {
errno = ret;
perror("opal_mutex_unlock");
abort();
opal_output(0, "opal_mutex_unlock() %d", ret);
}
#else
pthread_mutex_unlock(&m->m_lock_pthread);
@ -209,6 +211,15 @@ static inline void opal_mutex_atomic_unlock(opal_mutex_t *m)
#endif
typedef pthread_cond_t opal_cond_t;
#define OPAL_CONDITION_STATIC_INIT PTHREAD_COND_INITIALIZER
int opal_cond_init(opal_cond_t *cond);
int opal_cond_wait(opal_cond_t *cond, opal_mutex_t *lock);
int opal_cond_broadcast(opal_cond_t *cond);
int opal_cond_signal(opal_cond_t *cond);
int opal_cond_destroy(opal_cond_t *cond);
END_C_DECLS
#endif /* OPAL_MUTEX_UNIX_H */
#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_MUTEX_H */

Просмотреть файл

@ -0,0 +1,40 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H
#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H
#include <pthread.h>
#include <signal.h>
struct opal_thread_t {
opal_object_t super;
opal_thread_fn_t t_run;
void *t_arg;
pthread_t t_handle;
};
#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_THREADS_H */

Просмотреть файл

@ -0,0 +1,53 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H
#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H
#include <pthread.h>
#include <signal.h>
typedef pthread_key_t opal_tsd_key_t;
static inline int opal_tsd_key_delete(opal_tsd_key_t key)
{
int ret = pthread_key_delete(key);
return 0 == ret ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
}
static inline int opal_tsd_setspecific(opal_tsd_key_t key, void *value)
{
int ret = pthread_setspecific(key, value);
return 0 == ret ? OPAL_SUCCESS : OPAL_ERR_IN_ERRNO;
}
static inline int opal_tsd_getspecific(opal_tsd_key_t key, void **valuep)
{
*valuep = pthread_getspecific(key);
return OPAL_SUCCESS;
}
#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_TSD_H */

Просмотреть файл

@ -6,25 +6,28 @@
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
#include "wait_sync.h"
#include "opal/mca/threads/wait_sync.h"
static opal_mutex_t wait_sync_lock = OPAL_MUTEX_STATIC_INIT;
static ompi_wait_sync_t* wait_sync_list = NULL;
static ompi_wait_sync_t *wait_sync_list = NULL;
static opal_atomic_int32_t num_thread_in_progress = 0;
#define WAIT_SYNC_PASS_OWNERSHIP(who) \
do { \
pthread_mutex_lock( &(who)->lock); \
pthread_cond_signal( &(who)->condition ); \
pthread_mutex_unlock( &(who)->lock); \
} while(0)
#define WAIT_SYNC_PASS_OWNERSHIP(who) \
do { \
pthread_mutex_lock(&(who)->lock); \
pthread_cond_signal(&(who)->condition); \
pthread_mutex_unlock(&(who)->lock); \
} while (0)
int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
{
@ -32,8 +35,9 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
* race condition around the release of the synchronization using the
* signaling field.
*/
if(sync->count <= 0)
if (sync->count <= 0) {
return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR;
}
/* lock so nobody can signal us during the list updating */
pthread_mutex_lock(&sync->lock);
@ -41,14 +45,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
/* Now that we hold the lock make sure another thread has not already
* call cond_signal.
*/
if(sync->count <= 0) {
if (sync->count <= 0) {
pthread_mutex_unlock(&sync->lock);
return (0 == sync->status) ? OPAL_SUCCESS : OPAL_ERROR;
}
/* Insert sync on the list of pending synchronization constructs */
OPAL_THREAD_LOCK(&wait_sync_lock);
if( NULL == wait_sync_list ) {
if (NULL == wait_sync_list) {
sync->next = sync->prev = sync;
wait_sync_list = sync;
} else {
@ -60,12 +64,14 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
OPAL_THREAD_UNLOCK(&wait_sync_lock);
/**
* If we are not responsible for progresing, go silent until something worth noticing happen:
* If we are not responsible for progressing, go silent until something
* worth noticing happen:
* - this thread has been promoted to take care of the progress
* - our sync has been triggered.
*/
check_status:
if( sync != wait_sync_list && num_thread_in_progress >= opal_max_thread_in_progress) {
check_status:
if (sync != wait_sync_list &&
num_thread_in_progress >= opal_max_thread_in_progress) {
pthread_cond_wait(&sync->condition, &sync->lock);
/**
@ -74,7 +80,7 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
* promoted as the progress manager.
*/
if( sync->count <= 0 ) { /* Completed? */
if (sync->count <= 0) { /* Completed? */
pthread_mutex_unlock(&sync->lock);
goto i_am_done;
}
@ -84,21 +90,23 @@ int ompi_sync_wait_mt(ompi_wait_sync_t *sync)
pthread_mutex_unlock(&sync->lock);
OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, 1);
while(sync->count > 0) { /* progress till completion */
opal_progress(); /* don't progress with the sync lock locked or you'll deadlock */
while (sync->count > 0) { /* progress till completion */
/* don't progress with the sync lock locked or you'll deadlock */
opal_progress();
}
OPAL_THREAD_ADD_FETCH32(&num_thread_in_progress, -1);
i_am_done:
i_am_done:
/* My sync is now complete. Trim the list: remove self, wake next */
OPAL_THREAD_LOCK(&wait_sync_lock);
sync->prev->next = sync->next;
sync->next->prev = sync->prev;
/* In case I am the progress manager, pass the duties on */
if( sync == wait_sync_list ) {
if (sync == wait_sync_list) {
wait_sync_list = (sync == sync->next) ? NULL : sync->next;
if( NULL != wait_sync_list )
if (NULL != wait_sync_list) {
WAIT_SYNC_PASS_OWNERSHIP(wait_sync_list);
}
}
OPAL_THREAD_UNLOCK(&wait_sync_lock);

Просмотреть файл

@ -1,14 +1,21 @@
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2014-2016 The University of Tennessee and The University
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2006 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2007-2018 Los Alamos National Security, LLC. All rights
* reserved.
* Copyright (c) 2016 Mellanox Technologies. All rights reserved.
* Copyright (c) 2016 Research Organization for Information Science
* Copyright (c) 2015-2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2017 IBM Corporation. All rights reserved.
* Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
*
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -16,16 +23,9 @@
* $HEADER$
*/
#if !defined(OPAL_THREADS_WAIT_SYNC_H)
#define OPAL_THREADS_WAIT_SYNC_H
#include "opal/sys/atomic.h"
#include "opal/threads/condition.h"
#include <pthread.h>
BEGIN_C_DECLS
extern int opal_max_thread_in_progress;
#ifndef OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H
#define OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H
typedef struct ompi_wait_sync_t {
opal_atomic_int32_t count;
@ -37,10 +37,8 @@ typedef struct ompi_wait_sync_t {
volatile bool signaling;
} ompi_wait_sync_t;
#define REQUEST_PENDING (void*)0L
#define REQUEST_COMPLETED (void*)1L
#define SYNC_WAIT(sync) (opal_using_threads() ? ompi_sync_wait_mt (sync) : sync_wait_st (sync))
#define SYNC_WAIT(sync) \
(opal_using_threads() ? ompi_sync_wait_mt(sync) : sync_wait_st(sync))
/* The loop in release handles a race condition between the signaling
* thread and the destruction of the condition variable. The signaling
@ -74,21 +72,20 @@ typedef struct ompi_wait_sync_t {
sync->signaling = false; \
}
#define WAIT_SYNC_SIGNALLED(sync){ \
#define WAIT_SYNC_SIGNALLED(sync) \
{ \
(sync)->signaling = false; \
}
}
OPAL_DECLSPEC int ompi_sync_wait_mt(ompi_wait_sync_t *sync);
static inline int sync_wait_st (ompi_wait_sync_t *sync)
static inline int sync_wait_st(ompi_wait_sync_t *sync)
{
while (sync->count > 0) {
opal_progress();
}
return sync->status;
}
#define WAIT_SYNC_INIT(sync,c) \
do { \
(sync)->count = (c); \
@ -97,32 +94,9 @@ static inline int sync_wait_st (ompi_wait_sync_t *sync)
(sync)->status = 0; \
(sync)->signaling = (0 != (c)); \
if (opal_using_threads()) { \
pthread_cond_init (&(sync)->condition, NULL); \
pthread_mutex_init (&(sync)->lock, NULL); \
pthread_cond_init(&(sync)->condition, NULL); \
pthread_mutex_init(&(sync)->lock, NULL); \
} \
} while(0)
} while (0)
/**
* Update the status of the synchronization primitive. If an error is
* reported the synchronization is completed and the signal
* triggered. The status of the synchronization will be reported to
* the waiting threads.
*/
static inline void wait_sync_update(ompi_wait_sync_t *sync, int updates, int status)
{
if( OPAL_LIKELY(OPAL_SUCCESS == status) ) {
if( 0 != (OPAL_THREAD_ADD_FETCH32(&sync->count, -updates)) ) {
return;
}
} else {
/* this is an error path so just use the atomic */
sync->status = OPAL_ERROR;
opal_atomic_wmb ();
opal_atomic_swap_32 (&sync->count, 0);
}
WAIT_SYNC_SIGNAL(sync);
}
END_C_DECLS
#endif /* defined(OPAL_THREADS_WAIT_SYNC_H) */
#endif /* OPAL_MCA_THREADS_PTHREADS_THREADS_PTHREADS_WAIT_SYNC_H */

30
opal/mca/threads/qthreads/Makefile.am Обычный файл
Просмотреть файл

@ -0,0 +1,30 @@
#
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
# University Research and Technology
# Corporation. All rights reserved.
# Copyright (c) 2004-2005 The University of Tennessee and The University
# of Tennessee Research Foundation. All rights
# reserved.
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
# University of Stuttgart. All rights reserved.
# Copyright (c) 2004-2005 The Regents of the University of California.
# All rights reserved.
# Copyright (c) 2008 Cisco Systems, Inc. All rights reserved.
# Copyright (c) 2019 Sandia National Laboratories. All rights reserved.
#
# $COPYRIGHT$
#
# Additional copyrights may follow
#
# $HEADER$
#
noinst_LTLIBRARIES = libmca_threads_qthreads.la
libmca_threads_qthreads_la_SOURCES = \
threads_qthreads_component.c \
threads_qthreads_mutex.c \
threads_qthreads_condition.c \
threads_qthreads_module.c
AM_LDFLAGS = -lqthread

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше