2004-02-13 16:56:55 +03:00
|
|
|
#include <string.h>
|
2004-01-29 18:34:47 +03:00
|
|
|
#include "lam/threads/mutex.h"
|
2004-02-13 16:56:55 +03:00
|
|
|
#include "lam/util/output.h"
|
2004-01-29 18:34:47 +03:00
|
|
|
#include "mpi/proc/proc.h"
|
2004-02-13 16:56:55 +03:00
|
|
|
#include "mca/lam/pcm/pcm.h"
|
2004-01-29 18:34:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
static lam_list_t lam_proc_list;
|
|
|
|
static lam_mutex_t lam_proc_lock;
|
2004-02-13 16:56:55 +03:00
|
|
|
lam_proc_t* lam_proc_local_proc = NULL;
|
|
|
|
|
|
|
|
static void lam_proc_construct(lam_proc_t* proc);
|
|
|
|
static void lam_proc_destruct(lam_proc_t* proc);
|
2004-01-16 03:31:58 +03:00
|
|
|
|
|
|
|
|
2004-02-13 01:42:39 +03:00
|
|
|
lam_class_t lam_proc_t_class = {
|
2004-01-16 03:31:58 +03:00
|
|
|
"lam_proc_t",
|
2004-02-13 16:56:55 +03:00
|
|
|
OBJ_CLASS(lam_list_item_t),
|
2004-02-10 17:04:27 +03:00
|
|
|
(lam_construct_t)lam_proc_construct,
|
|
|
|
(lam_destruct_t)lam_proc_destruct
|
2004-01-16 03:31:58 +03:00
|
|
|
};
|
|
|
|
|
2004-02-10 17:04:27 +03:00
|
|
|
void lam_proc_construct(lam_proc_t* proc)
|
2004-01-16 03:31:58 +03:00
|
|
|
{
|
2004-01-29 18:34:47 +03:00
|
|
|
static int init = 0;
|
2004-02-10 19:53:41 +03:00
|
|
|
if(fetchNset(&init,1) == 0) {
|
|
|
|
OBJ_CONSTRUCT(&lam_proc_list, lam_list_t);
|
2004-03-03 19:44:41 +03:00
|
|
|
OBJ_CONSTRUCT(&lam_proc_lock, lam_mutex_t);
|
2004-01-29 18:34:47 +03:00
|
|
|
}
|
|
|
|
|
2004-02-14 01:16:39 +03:00
|
|
|
proc->proc_job = NULL;
|
2004-01-16 03:31:58 +03:00
|
|
|
proc->proc_vpid = 0;
|
2004-02-14 01:16:39 +03:00
|
|
|
proc->proc_pml = NULL;
|
|
|
|
proc->proc_modex = NULL;
|
2004-01-29 18:34:47 +03:00
|
|
|
|
|
|
|
THREAD_LOCK(&lam_proc_lock);
|
|
|
|
lam_list_append(&lam_proc_list, (lam_list_item_t*)proc);
|
|
|
|
THREAD_UNLOCK(&lam_proc_lock);
|
2004-01-16 03:31:58 +03:00
|
|
|
}
|
|
|
|
|
2004-01-29 18:34:47 +03:00
|
|
|
|
2004-02-10 17:04:27 +03:00
|
|
|
void lam_proc_destruct(lam_proc_t* proc)
|
2004-01-16 03:31:58 +03:00
|
|
|
{
|
2004-01-29 18:34:47 +03:00
|
|
|
THREAD_LOCK(&lam_proc_lock);
|
|
|
|
lam_list_remove_item(&lam_proc_list, (lam_list_item_t*)proc);
|
|
|
|
THREAD_UNLOCK(&lam_proc_lock);
|
2004-01-16 03:31:58 +03:00
|
|
|
}
|
|
|
|
|
2004-02-13 16:56:55 +03:00
|
|
|
|
|
|
|
int lam_proc_init(void)
|
|
|
|
{
|
|
|
|
mca_pcm_proc_t *procs;
|
|
|
|
mca_pcm_proc_t *local;
|
|
|
|
size_t i, nprocs;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if(LAM_SUCCESS != (rc = mca_pcm.pcm_proc_startup())) {
|
|
|
|
lam_output(0, "lam_proc_init: pcm_proc_startup failed with errno=%d", rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(NULL == (local = mca_pcm.pcm_proc_get_me())) {
|
|
|
|
lam_output(0, "lam_proc_init: unable to determine local proc id");
|
|
|
|
return LAM_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(LAM_SUCCESS != (rc = mca_pcm.pcm_proc_get_peers(&procs, &nprocs))) {
|
|
|
|
lam_output(0, "lam_proc_init: pcm_proc_get_peers failed with errno=%d", rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i<nprocs; i++) {
|
2004-02-13 17:47:01 +03:00
|
|
|
lam_job_handle_t job = procs[i].job_handle;
|
|
|
|
uint32_t vpid = procs[i].vpid;
|
2004-02-13 16:56:55 +03:00
|
|
|
lam_proc_t *proc = OBJ_NEW(lam_proc_t);
|
2004-02-13 17:47:01 +03:00
|
|
|
proc->proc_job = strdup(job);
|
|
|
|
proc->proc_vpid = vpid;
|
2004-03-03 19:44:41 +03:00
|
|
|
if(proc->proc_vpid == local->vpid && strcmp(proc->proc_job, local->job_handle) == 0) {
|
2004-02-13 17:47:01 +03:00
|
|
|
lam_proc_local_proc = proc;
|
2004-03-03 19:44:41 +03:00
|
|
|
}
|
2004-02-13 16:56:55 +03:00
|
|
|
}
|
|
|
|
free(procs);
|
|
|
|
return LAM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lam_proc_t** lam_proc_world(size_t *size)
|
|
|
|
{
|
|
|
|
lam_proc_t **procs = malloc(lam_list_get_size(&lam_proc_list) * sizeof(lam_proc_t*));
|
|
|
|
lam_proc_t *proc;
|
|
|
|
lam_job_handle_t job;
|
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
if(NULL == procs)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if(NULL == (job = mca_pcm.pcm_handle_get()))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* return only the procs that match this jobid */
|
|
|
|
THREAD_LOCK(&lam_proc_lock);
|
|
|
|
for(proc = (lam_proc_t*)lam_list_get_first(&lam_proc_list);
|
|
|
|
proc != (lam_proc_t*)lam_list_get_end(&lam_proc_list);
|
|
|
|
proc = (lam_proc_t*)lam_list_get_next(proc)) {
|
|
|
|
if(strcmp(proc->proc_job,job) == 0) {
|
|
|
|
OBJ_RETAIN(proc);
|
|
|
|
procs[count++] = proc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
THREAD_UNLOCK(&lam_proc_lock);
|
|
|
|
*size = count;
|
|
|
|
return procs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lam_proc_t** lam_proc_all(size_t* size)
|
|
|
|
{
|
|
|
|
lam_proc_t **procs = malloc(lam_list_get_size(&lam_proc_list) * sizeof(lam_proc_t*));
|
|
|
|
lam_proc_t *proc;
|
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
if(NULL == procs)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
THREAD_LOCK(&lam_proc_lock);
|
|
|
|
for(proc = (lam_proc_t*)lam_list_get_first(&lam_proc_list);
|
|
|
|
proc != (lam_proc_t*)lam_list_get_end(&lam_proc_list);
|
|
|
|
proc = (lam_proc_t*)lam_list_get_next(proc)) {
|
|
|
|
OBJ_RETAIN(proc);
|
|
|
|
procs[count++] = proc;
|
|
|
|
}
|
|
|
|
THREAD_UNLOCK(&lam_proc_lock);
|
|
|
|
*size = count;
|
|
|
|
return procs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lam_proc_t** lam_proc_self(size_t* size)
|
|
|
|
{
|
|
|
|
lam_proc_t **procs = malloc(sizeof(lam_proc_t*));
|
|
|
|
if(NULL == procs)
|
|
|
|
return NULL;
|
|
|
|
OBJ_RETAIN(lam_proc_local_proc);
|
|
|
|
*procs = lam_proc_local_proc;
|
|
|
|
*size = 1;
|
|
|
|
return procs;
|
|
|
|
}
|
|
|
|
|