Skip to content

Commit

Permalink
Merge pull request #347 from edoapra/solaris-comex
Browse files Browse the repository at this point in the history
fix for comex on Solaris
  • Loading branch information
edoapra authored Aug 6, 2024
2 parents c051af7 + 7eee4cd commit b9c55c7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 33 deletions.
16 changes: 8 additions & 8 deletions comex/src-mpi-mt/comex.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ typedef struct {
typedef struct lock_link {
struct lock_link *next;
int rank;
} lock_t;
} comex_lock_t;


typedef struct {
Expand Down Expand Up @@ -112,7 +112,7 @@ typedef struct {
/* static state */
static int *num_mutexes = NULL; /**< (all) how many mutexes on each process */
static int **mutexes = NULL; /**< (masters) value is rank of lock holder */
static lock_t ***lq_heads = NULL; /**< array of lock queues */
static comex_lock_t ***lq_heads = NULL; /**< array of lock queues */
static int initialized = 0; /* for comex_initialized(), 0=false */
static char *fence_array = NULL;
static pthread_t progress_thread;
Expand Down Expand Up @@ -317,7 +317,7 @@ int _comex_init(MPI_Comm comm)
COMEX_ASSERT(mutexes);

/* create one lock queue for each proc for each mutex */
lq_heads = (lock_t***)malloc(sizeof(lock_t**) * g_state.size);
lq_heads = (comex_lock_t***)malloc(sizeof(comex_lock_t**) * g_state.size);
COMEX_ASSERT(lq_heads);

/* start the server (each rank does this) */
Expand Down Expand Up @@ -2372,7 +2372,7 @@ STATIC void _mutex_create_handler(header_t *header, int proc)
#endif

mutexes[proc] = (int*)malloc(sizeof(int) * num);
lq_heads[proc] = (lock_t**)malloc(sizeof(lock_t*) * num);
lq_heads[proc] = (comex_lock_t**)malloc(sizeof(comex_lock_t*) * num);
for (i=0; i<num; ++i) {
mutexes[proc][i] = UNLOCKED;
lq_heads[proc][i] = NULL;
Expand Down Expand Up @@ -2420,18 +2420,18 @@ STATIC void _lock_handler(header_t *header, int proc)
server_send(&id, sizeof(int), proc);
}
else {
lock_t *lock = NULL;
comex_lock_t *lock = NULL;
#if DEBUG
printf("[%d] _lq_push rank=%d req_by=%d id=%d\n",
g_state.rank, rank, proc, id);
#endif
lock = malloc(sizeof(lock_t));
lock = malloc(sizeof(comex_lock_t));
lock->next = NULL;
lock->rank = proc;

if (lq_heads[rank][id]) {
/* insert at tail */
lock_t *lq = lq_heads[rank][id];
comex_lock_t *lq = lq_heads[rank][id];
while (lq->next) {
lq = lq->next;
}
Expand Down Expand Up @@ -2460,7 +2460,7 @@ STATIC void _unlock_handler(header_t *header, int proc)
if (lq_heads[rank][id]) {
/* a lock requester was queued */
/* find the next lock request and update queue */
lock_t *lock = lq_heads[rank][id];
comex_lock_t *lock = lq_heads[rank][id];
lq_heads[rank][id] = lq_heads[rank][id]->next;
/* update lock */
mutexes[rank][id] = lock->rank;
Expand Down
19 changes: 11 additions & 8 deletions comex/src-mpi-pr/comex.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <semaphore.h>
#include <signal.h>
#include <stdio.h>
#if HAVE_ERRNO_H
# include <errno.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <strings.h>
Expand Down Expand Up @@ -122,7 +125,7 @@ typedef struct {
typedef struct lock_link {
struct lock_link *next;
int rank;
} lock_t;
} comex_lock_t;


typedef struct {
Expand Down Expand Up @@ -164,7 +167,7 @@ typedef struct {
/* static state */
static int *num_mutexes = NULL; /**< (all) how many mutexes on each process */
static int **mutexes = NULL; /**< (masters) value is rank of lock holder */
static lock_t ***lq_heads = NULL; /**< array of lock queues */
static comex_lock_t ***lq_heads = NULL; /**< array of lock queues */
static char *sem_name = NULL; /* local semaphore name */
static sem_t **semaphores = NULL; /* semaphores for locking within SMP node */
static int initialized = 0; /* for comex_initialized(), 0=false */
Expand Down Expand Up @@ -676,7 +679,7 @@ int _comex_init(MPI_Comm comm)
mutexes = (int**)malloc(sizeof(int*) * g_state.size);
COMEX_ASSERT(mutexes);
/* create one lock queue for each proc for each mutex */
lq_heads = (lock_t***)malloc(sizeof(lock_t**) * g_state.size);
lq_heads = (comex_lock_t***)malloc(sizeof(comex_lock_t**) * g_state.size);
COMEX_ASSERT(lq_heads);
/* start the server */
_progress_server();
Expand Down Expand Up @@ -4516,7 +4519,7 @@ STATIC void _mutex_create_handler(header_t *header, int proc)
#endif

mutexes[proc] = (int*)malloc(sizeof(int) * num);
lq_heads[proc] = (lock_t**)malloc(sizeof(lock_t*) * num);
lq_heads[proc] = (comex_lock_t**)malloc(sizeof(comex_lock_t*) * num);
for (i=0; i<num; ++i) {
mutexes[proc][i] = UNLOCKED;
lq_heads[proc][i] = NULL;
Expand Down Expand Up @@ -4564,18 +4567,18 @@ STATIC void _lock_handler(header_t *header, int proc)
server_send(&id, sizeof(int), proc);
}
else {
lock_t *lock = NULL;
comex_lock_t *lock = NULL;
#if DEBUG
fprintf(stderr, "[%d] _lq_push rank=%d req_by=%d id=%d\n",
g_state.rank, rank, proc, id);
#endif
lock = malloc(sizeof(lock_t));
lock = malloc(sizeof(comex_lock_t));
lock->next = NULL;
lock->rank = proc;

if (lq_heads[rank][id]) {
/* insert at tail */
lock_t *lq = lq_heads[rank][id];
comex_lock_t *lq = lq_heads[rank][id];
while (lq->next) {
lq = lq->next;
}
Expand Down Expand Up @@ -4604,7 +4607,7 @@ STATIC void _unlock_handler(header_t *header, int proc)
if (lq_heads[rank][id]) {
/* a lock requester was queued */
/* find the next lock request and update queue */
lock_t *lock = lq_heads[rank][id];
comex_lock_t *lock = lq_heads[rank][id];
lq_heads[rank][id] = lq_heads[rank][id]->next;
/* update lock */
mutexes[rank][id] = lock->rank;
Expand Down
19 changes: 11 additions & 8 deletions comex/src-mpi-pt/comex.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <fcntl.h>
#include <semaphore.h>
#include <stdio.h>
#if HAVE_ERRNO_H
# include <errno.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <strings.h>
Expand Down Expand Up @@ -91,7 +94,7 @@ typedef struct {
typedef struct lock_link {
struct lock_link *next;
int rank;
} lock_t;
} comex_lock_t;


typedef struct {
Expand Down Expand Up @@ -132,7 +135,7 @@ typedef struct {
/* static state */
static int *num_mutexes = NULL; /**< (all) how many mutexes on each process */
static int **mutexes = NULL; /**< (masters) value is rank of lock holder */
static lock_t ***lq_heads = NULL; /**< array of lock queues */
static comex_lock_t ***lq_heads = NULL; /**< array of lock queues */
static char *sem_name = NULL; /* local semaphore name */
static sem_t **semaphores = NULL; /* semaphores for locking within SMP node */
static int initialized = 0; /* for comex_initialized(), 0=false */
Expand Down Expand Up @@ -382,7 +385,7 @@ int _comex_init(MPI_Comm comm)
mutexes = (int**)malloc(sizeof(int*) * g_state.size);
COMEX_ASSERT(mutexes);
/* create one lock queue for each proc for each mutex */
lq_heads = (lock_t***)malloc(sizeof(lock_t**) * g_state.size);
lq_heads = (comex_lock_t***)malloc(sizeof(comex_lock_t**) * g_state.size);
COMEX_ASSERT(lq_heads);
/* start the server */
pthread_create(&progress_thread, NULL, _progress_server, NULL);
Expand Down Expand Up @@ -3306,7 +3309,7 @@ STATIC void _mutex_create_handler(header_t *header, int proc)
#endif

mutexes[proc] = (int*)malloc(sizeof(int) * num);
lq_heads[proc] = (lock_t**)malloc(sizeof(lock_t*) * num);
lq_heads[proc] = (comex_lock_t**)malloc(sizeof(comex_lock_t*) * num);
for (i=0; i<num; ++i) {
mutexes[proc][i] = UNLOCKED;
lq_heads[proc][i] = NULL;
Expand Down Expand Up @@ -3354,18 +3357,18 @@ STATIC void _lock_handler(header_t *header, int proc)
server_send(&id, sizeof(int), proc);
}
else {
lock_t *lock = NULL;
comex_lock_t *lock = NULL;
#if DEBUG
printf("[%d] _lq_push rank=%d req_by=%d id=%d\n",
g_state.rank, rank, proc, id);
#endif
lock = malloc(sizeof(lock_t));
lock = malloc(sizeof(comex_lock_t));
lock->next = NULL;
lock->rank = proc;

if (lq_heads[rank][id]) {
/* insert at tail */
lock_t *lq = lq_heads[rank][id];
comex_lock_t *lq = lq_heads[rank][id];
while (lq->next) {
lq = lq->next;
}
Expand Down Expand Up @@ -3394,7 +3397,7 @@ STATIC void _unlock_handler(header_t *header, int proc)
if (lq_heads[rank][id]) {
/* a lock requester was queued */
/* find the next lock request and update queue */
lock_t *lock = lq_heads[rank][id];
comex_lock_t *lock = lq_heads[rank][id];
lq_heads[rank][id] = lq_heads[rank][id]->next;
/* update lock */
mutexes[rank][id] = lock->rank;
Expand Down
12 changes: 6 additions & 6 deletions comex/src-mpi/comex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1909,13 +1909,13 @@ static void _unlock_request_handler(header_t *header, int proc)

static void _lq_push(int rank, int id, char *notify)
{
lock_t *lock = NULL;
comex_lock_t *lock = NULL;

#if DEBUG
printf("[%d] _lq_push rank=%d id=%d\n", l_state.rank, rank, id);
#endif

lock = _my_malloc(sizeof(lock_t));
lock = _my_malloc(sizeof(comex_lock_t));
lock->next = NULL;
lock->rank = rank;
lock->id = id;
Expand Down Expand Up @@ -1943,9 +1943,9 @@ static void _lq_push(int rank, int id, char *notify)
static int _lq_progress(void)
{
int needs_progress = 0;
lock_t *lock = NULL;
lock_t *new_lock_head = NULL;
lock_t *new_lock_tail = NULL;
comex_lock_t *lock = NULL;
comex_lock_t *new_lock_head = NULL;
comex_lock_t *new_lock_tail = NULL;

#if DEBUG
if (l_state.num_mutexes > 0) {
Expand All @@ -1960,7 +1960,7 @@ static int _lq_progress(void)
lock = l_state.lq_head;
while (lock) {
if (l_state.mutexes[lock->id] < 0) {
lock_t *last = NULL;
comex_lock_t *last = NULL;
header_t *header = NULL;

l_state.mutexes[lock->id] = lock->rank;
Expand Down
6 changes: 3 additions & 3 deletions comex/src-mpi/comex_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef struct lock_link {
int rank;
int id;
void *notify_address;
} lock_t;
} comex_lock_t;

typedef struct {
MPI_Comm world_comm;
Expand All @@ -86,8 +86,8 @@ typedef struct {
barrier_t *bq_tail;

/* a queue for lock requests */
lock_t *lq_head;
lock_t *lq_tail;
comex_lock_t *lq_head;
comex_lock_t *lq_tail;

} local_state;

Expand Down

0 comments on commit b9c55c7

Please sign in to comment.