- Implement MPI_Is_thread_main
- Add new thread function to compare current thread to an ompi_thread_t* - Save current thread ID in MPI_INIT* - Add first cut of solaris thread functions - Add stubs for missing Windows thread functions This commit was SVN r3569.
Этот коммит содержится в:
родитель
e5aa5ddc9b
Коммит
7f3790615a
@ -144,7 +144,7 @@ static int ompi_event_pipe_signalled;
|
||||
bool ompi_event_progress_thread(void)
|
||||
{
|
||||
#if OMPI_HAVE_THREADS
|
||||
return ompi_thread_self(&ompi_event_thread);
|
||||
return ompi_thread_self_compare(&ompi_event_thread);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
@ -6,8 +6,10 @@
|
||||
|
||||
#include "mpi.h"
|
||||
#include "mpi/c/bindings.h"
|
||||
#include "mpi/runtime/mpiruntime.h"
|
||||
#include "communicator/communicator.h"
|
||||
#include "errhandler/errhandler.h"
|
||||
#include "threads/thread.h"
|
||||
|
||||
#if OMPI_HAVE_WEAK_SYMBOLS && OMPI_PROFILING_DEFINES
|
||||
#pragma weak MPI_Is_thread_main = PMPI_Is_thread_main
|
||||
@ -22,11 +24,20 @@ static const char FUNC_NAME[] = "MPI_Is_thread_main";
|
||||
|
||||
int MPI_Is_thread_main(int *flag)
|
||||
{
|
||||
if (MPI_PARAM_CHECK) {
|
||||
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
|
||||
}
|
||||
if (MPI_PARAM_CHECK) {
|
||||
OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
|
||||
if (NULL == flag) {
|
||||
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM, FUNC_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
/* This function is not yet implemented */
|
||||
/* Compare this thread ID to the main thread ID */
|
||||
|
||||
return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_OTHER, FUNC_NAME);
|
||||
#if OMPI_HAVE_THREADS
|
||||
*flag = (int) ompi_thread_self_compare(ompi_mpi_main_thread);
|
||||
#else
|
||||
*flag = 1;
|
||||
#endif
|
||||
|
||||
return MPI_SUCCESS;
|
||||
}
|
||||
|
@ -16,25 +16,26 @@
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
/* forward type declarations */
|
||||
/** forward type declaration */
|
||||
struct ompi_communicator_t;
|
||||
/** forward type declaration */
|
||||
struct ompi_thread_t;
|
||||
|
||||
/*
|
||||
* Global variables and symbols for the MPI layer
|
||||
*/
|
||||
/* Global variables and symbols for the MPI layer */
|
||||
|
||||
/** Is mpi initialized? */
|
||||
OMPI_DECLSPEC extern bool ompi_mpi_initialized;
|
||||
/** Has mpi been finalized? */
|
||||
OMPI_DECLSPEC extern bool ompi_mpi_finalized;
|
||||
|
||||
/** Do we have multiple threads? */
|
||||
OMPI_DECLSPEC extern bool ompi_mpi_thread_multiple;
|
||||
/** Thread level requested to \c MPI_Init_thread() */
|
||||
OMPI_DECLSPEC extern int ompi_mpi_thread_requested;
|
||||
/** Thread level provided by Open MPI */
|
||||
OMPI_DECLSPEC extern int ompi_mpi_thread_provided;
|
||||
/** Is mpi initialized? */
|
||||
OMPI_DECLSPEC extern bool ompi_mpi_initialized;
|
||||
/** Has mpi been finalized? */
|
||||
OMPI_DECLSPEC extern bool ompi_mpi_finalized;
|
||||
|
||||
/** Do we have multiple threads? */
|
||||
OMPI_DECLSPEC extern bool ompi_mpi_thread_multiple;
|
||||
/** Thread level requested to \c MPI_Init_thread() */
|
||||
OMPI_DECLSPEC extern int ompi_mpi_thread_requested;
|
||||
/** Thread level provided by Open MPI */
|
||||
OMPI_DECLSPEC extern int ompi_mpi_thread_provided;
|
||||
/** Identifier of the main thread */
|
||||
OMPI_DECLSPEC extern struct ompi_thread_t *ompi_mpi_main_thread;
|
||||
|
||||
|
||||
/**
|
||||
@ -74,7 +75,6 @@ OMPI_DECLSPEC extern int ompi_mpi_thread_provided;
|
||||
int ompi_mpi_abort(struct ompi_communicator_t* comm,
|
||||
int errcode, bool kill_remote_of_intercomm);
|
||||
|
||||
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "op/op.h"
|
||||
#include "file/file.h"
|
||||
#include "attribute/attribute.h"
|
||||
#include "threads/thread.h"
|
||||
|
||||
#include "mca/base/base.h"
|
||||
#include "mca/base/base.h"
|
||||
@ -57,6 +58,8 @@ bool ompi_mpi_thread_multiple = false;
|
||||
int ompi_mpi_thread_requested = MPI_THREAD_SINGLE;
|
||||
int ompi_mpi_thread_provided = MPI_THREAD_SINGLE;
|
||||
|
||||
ompi_thread_t *ompi_mpi_main_thread = NULL;
|
||||
|
||||
|
||||
int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
|
||||
{
|
||||
@ -275,6 +278,11 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
|
||||
ompi_mpi_thread_provided = *provided;
|
||||
ompi_mpi_thread_multiple = (ompi_mpi_thread_provided ==
|
||||
MPI_THREAD_MULTIPLE);
|
||||
#if OMPI_HAVE_THREADS
|
||||
ompi_mpi_main_thread = ompi_thread_get_self();
|
||||
#else
|
||||
ompi_mpi_main_thread = NULL;
|
||||
#endif
|
||||
|
||||
/* Init coll for the comms */
|
||||
|
||||
|
@ -8,6 +8,16 @@
|
||||
#include "threads/thread.h"
|
||||
|
||||
|
||||
static void ompi_thread_construct(ompi_thread_t *t);
|
||||
|
||||
OBJ_CLASS_INSTANCE(ompi_thread_t,
|
||||
ompi_object_t,
|
||||
ompi_thread_construct, NULL);
|
||||
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
static void ompi_thread_construct(ompi_thread_t *t)
|
||||
{
|
||||
t->t_run = 0;
|
||||
@ -15,25 +25,17 @@ static void ompi_thread_construct(ompi_thread_t *t)
|
||||
t->t_handle = (HANDLE) -1;
|
||||
#elif OMPI_HAVE_POSIX_THREADS
|
||||
t->t_handle = (pthread_t) -1;
|
||||
#elif OMPI_HAVE_SOLARIS_THREADS
|
||||
t->t_handle = (thread_t) -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static void ompi_thread_destruct(ompi_thread_t *t)
|
||||
{
|
||||
}
|
||||
#if defined(WIN32)
|
||||
|
||||
|
||||
OBJ_CLASS_INSTANCE(ompi_thread_t,
|
||||
ompi_object_t,
|
||||
ompi_thread_construct,
|
||||
ompi_thread_destruct);
|
||||
|
||||
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
#error Windows code is untested
|
||||
/************************************************************************
|
||||
* Windows threads
|
||||
************************************************************************/
|
||||
|
||||
int ompi_thread_start(ompi_thread_t *t)
|
||||
{
|
||||
@ -77,8 +79,27 @@ int ompi_thread_join(ompi_thread_t *t, void **thr_return)
|
||||
}
|
||||
|
||||
|
||||
bool ompi_thread_self_compare(ompi_thread_t *t)
|
||||
{
|
||||
#error Need Windows thread_self() function
|
||||
}
|
||||
|
||||
|
||||
ompi_thread_t *ompi_thread_get_self(void)
|
||||
{
|
||||
ompi_thread_t *t = OBJ_NEW(ompi_thread_t);
|
||||
#error Need Windows thread_self() function
|
||||
t->t_handle = ....something....
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#elif OMPI_HAVE_POSIX_THREADS
|
||||
|
||||
/************************************************************************
|
||||
* POSIX threads
|
||||
************************************************************************/
|
||||
|
||||
int ompi_thread_start(ompi_thread_t *t)
|
||||
{
|
||||
@ -102,13 +123,71 @@ int ompi_thread_join(ompi_thread_t *t, void **thr_return)
|
||||
return (rc == 0) ? OMPI_SUCCESS : OMPI_ERROR;
|
||||
}
|
||||
|
||||
bool ompi_thread_self(ompi_thread_t *t)
|
||||
|
||||
bool ompi_thread_self_compare(ompi_thread_t *t)
|
||||
{
|
||||
return t->t_handle == pthread_self();
|
||||
}
|
||||
|
||||
|
||||
ompi_thread_t *ompi_thread_get_self(void)
|
||||
{
|
||||
ompi_thread_t *t = OBJ_NEW(ompi_thread_t);
|
||||
t->t_handle = pthread_self();
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
#elif OMPI_HAVE_SOLARIS_THREADS
|
||||
|
||||
/************************************************************************
|
||||
* Solaris threads
|
||||
************************************************************************/
|
||||
|
||||
#else
|
||||
|
||||
int ompi_thread_start(ompi_thread_t *t)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (OMPI_ENABLE_DEBUG) {
|
||||
if (NULL == t->t_run || t->t_handle != (pthread_t) -1) {
|
||||
return OMPI_ERR_BAD_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
rc = thr_create(NULL, 0, (void*(*)(void*)) t->t_run, t, NULL,
|
||||
&t->t_handle);
|
||||
|
||||
return (rc == 0) ? OMPI_SUCCESS : OMPI_ERROR;
|
||||
}
|
||||
|
||||
|
||||
int ompi_thread_join(ompi_thread_t *t, void **thr_return)
|
||||
{
|
||||
int rc = thread_join(t->t_handle, NULL, thr_return);
|
||||
return (rc == 0) ? OMPI_SUCCESS : OMPI_ERROR;
|
||||
}
|
||||
|
||||
|
||||
bool ompi_thread_self_compare(ompi_thread_t *t)
|
||||
{
|
||||
return t->t_handle == thr_self();
|
||||
}
|
||||
|
||||
|
||||
ompi_thread_t *ompi_thread_get_self(void)
|
||||
{
|
||||
ompi_thread_t *t = OBJ_NEW(ompi_thread_t);
|
||||
t->t_handle = thr_self();
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* No thread support
|
||||
************************************************************************/
|
||||
|
||||
|
||||
int ompi_thread_start(ompi_thread_t *t)
|
||||
{
|
||||
@ -121,9 +200,16 @@ int ompi_thread_join(ompi_thread_t *t, void **thr_return)
|
||||
return OMPI_ERROR;
|
||||
}
|
||||
|
||||
bool ompi_thread_self(ompi_thread_t *t)
|
||||
|
||||
bool ompi_thread_self_compare(ompi_thread_t *t)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ompi_thread_t *ompi_thread_get_self(void)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -29,6 +29,8 @@ struct ompi_thread_t {
|
||||
HANDLE t_handle;
|
||||
#elif OMPI_HAVE_POSIX_THREADS
|
||||
pthread_t t_handle;
|
||||
#elif OMPI_HAVE_SOLARIS_THREADS
|
||||
thread_t t_handle;
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -40,7 +42,8 @@ OMPI_DECLSPEC OBJ_CLASS_DECLARATION(ompi_thread_t);
|
||||
|
||||
int ompi_thread_start(ompi_thread_t *);
|
||||
int ompi_thread_join(ompi_thread_t *, void **thread_return);
|
||||
bool ompi_thread_self(ompi_thread_t*);
|
||||
bool ompi_thread_self_compare(ompi_thread_t*);
|
||||
ompi_thread_t *ompi_thread_get_self(void);
|
||||
#if defined(c_plusplus) || defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user