2004-02-13 16:56:55 +03:00
|
|
|
#include <string.h>
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "threads/mutex.h"
|
|
|
|
#include "util/output.h"
|
|
|
|
#include "proc/proc.h"
|
|
|
|
#include "mca/pcm/pcm.h"
|
2004-01-29 18:34:47 +03:00
|
|
|
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
static ompi_list_t ompi_proc_list;
|
|
|
|
static ompi_mutex_t ompi_proc_lock;
|
|
|
|
ompi_proc_t* ompi_proc_local_proc = NULL;
|
2004-02-13 16:56:55 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
static void ompi_proc_construct(ompi_proc_t* proc);
|
|
|
|
static void ompi_proc_destruct(ompi_proc_t* proc);
|
2004-01-16 03:31:58 +03:00
|
|
|
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_class_t ompi_proc_t_class = {
|
|
|
|
"ompi_proc_t",
|
|
|
|
OBJ_CLASS(ompi_list_item_t),
|
|
|
|
(ompi_construct_t)ompi_proc_construct,
|
|
|
|
(ompi_destruct_t)ompi_proc_destruct
|
2004-01-16 03:31:58 +03:00
|
|
|
};
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
void ompi_proc_construct(ompi_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) {
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_CONSTRUCT(&ompi_proc_list, ompi_list_t);
|
|
|
|
OBJ_CONSTRUCT(&ompi_proc_lock, ompi_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-03-26 17:15:20 +03:00
|
|
|
proc->proc_arch = 0;
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_CONSTRUCT(&proc->proc_lock, ompi_mutex_t);
|
2004-03-26 17:15:20 +03:00
|
|
|
|
|
|
|
/* FIX - need to determine remote process architecture */
|
2004-06-07 19:33:53 +04:00
|
|
|
proc->proc_convertor = ompi_convertor_create(0, 0);
|
2004-01-29 18:34:47 +03:00
|
|
|
|
2004-06-25 01:09:55 +04:00
|
|
|
THREAD_LOCK(&ompi_proc_lock);
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_list_append(&ompi_proc_list, (ompi_list_item_t*)proc);
|
2004-06-25 01:09:55 +04:00
|
|
|
THREAD_UNLOCK(&ompi_proc_lock);
|
2004-01-16 03:31:58 +03:00
|
|
|
}
|
|
|
|
|
2004-01-29 18:34:47 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
void ompi_proc_destruct(ompi_proc_t* proc)
|
2004-01-16 03:31:58 +03:00
|
|
|
{
|
2004-06-25 01:09:55 +04:00
|
|
|
THREAD_LOCK(&ompi_proc_lock);
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_list_remove_item(&ompi_proc_list, (ompi_list_item_t*)proc);
|
2004-06-25 01:09:55 +04:00
|
|
|
THREAD_UNLOCK(&ompi_proc_lock);
|
2004-03-31 20:59:06 +04:00
|
|
|
OBJ_DESTRUCT(&proc->proc_lock);
|
2004-01-16 03:31:58 +03:00
|
|
|
}
|
|
|
|
|
2004-02-13 16:56:55 +03:00
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
int ompi_proc_init(void)
|
2004-02-13 16:56:55 +03:00
|
|
|
{
|
|
|
|
mca_pcm_proc_t *procs;
|
|
|
|
mca_pcm_proc_t *local;
|
|
|
|
size_t i, nprocs;
|
|
|
|
int rc;
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
if(OMPI_SUCCESS != (rc = mca_pcm.pcm_proc_startup())) {
|
|
|
|
ompi_output(0, "ompi_proc_init: pcm_proc_startup failed with errno=%d", rc);
|
2004-02-13 16:56:55 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(NULL == (local = mca_pcm.pcm_proc_get_me())) {
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_output(0, "ompi_proc_init: unable to determine local proc id");
|
|
|
|
return OMPI_ERROR;
|
2004-02-13 16:56:55 +03:00
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
if(OMPI_SUCCESS != (rc = mca_pcm.pcm_proc_get_peers(&procs, &nprocs))) {
|
|
|
|
ompi_output(0, "ompi_proc_init: pcm_proc_get_peers failed with errno=%d", rc);
|
2004-02-13 16:56:55 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i=0; i<nprocs; i++) {
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_job_handle_t job = procs[i].job_handle;
|
2004-02-13 17:47:01 +03:00
|
|
|
uint32_t vpid = procs[i].vpid;
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t *proc = OBJ_NEW(ompi_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-06-07 19:33:53 +04:00
|
|
|
ompi_proc_local_proc = proc;
|
2004-03-03 19:44:41 +03:00
|
|
|
}
|
2004-02-13 16:56:55 +03:00
|
|
|
}
|
|
|
|
free(procs);
|
2004-06-07 19:33:53 +04:00
|
|
|
return OMPI_SUCCESS;
|
2004-02-13 16:56:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t** ompi_proc_world(size_t *size)
|
2004-02-13 16:56:55 +03:00
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t **procs = malloc(ompi_list_get_size(&ompi_proc_list) * sizeof(ompi_proc_t*));
|
|
|
|
ompi_proc_t *proc;
|
|
|
|
ompi_job_handle_t job;
|
2004-02-13 16:56:55 +03:00
|
|
|
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 */
|
2004-06-25 01:09:55 +04:00
|
|
|
THREAD_LOCK(&ompi_proc_lock);
|
2004-06-07 19:33:53 +04:00
|
|
|
for(proc = (ompi_proc_t*)ompi_list_get_first(&ompi_proc_list);
|
|
|
|
proc != (ompi_proc_t*)ompi_list_get_end(&ompi_proc_list);
|
|
|
|
proc = (ompi_proc_t*)ompi_list_get_next(proc)) {
|
2004-02-13 16:56:55 +03:00
|
|
|
if(strcmp(proc->proc_job,job) == 0) {
|
|
|
|
OBJ_RETAIN(proc);
|
|
|
|
procs[count++] = proc;
|
|
|
|
}
|
|
|
|
}
|
2004-06-25 01:09:55 +04:00
|
|
|
THREAD_UNLOCK(&ompi_proc_lock);
|
2004-02-13 16:56:55 +03:00
|
|
|
*size = count;
|
|
|
|
return procs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t** ompi_proc_all(size_t* size)
|
2004-02-13 16:56:55 +03:00
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t **procs = malloc(ompi_list_get_size(&ompi_proc_list) * sizeof(ompi_proc_t*));
|
|
|
|
ompi_proc_t *proc;
|
2004-02-13 16:56:55 +03:00
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
if(NULL == procs)
|
|
|
|
return NULL;
|
|
|
|
|
2004-06-25 01:09:55 +04:00
|
|
|
THREAD_LOCK(&ompi_proc_lock);
|
2004-06-07 19:33:53 +04:00
|
|
|
for(proc = (ompi_proc_t*)ompi_list_get_first(&ompi_proc_list);
|
|
|
|
proc != (ompi_proc_t*)ompi_list_get_end(&ompi_proc_list);
|
|
|
|
proc = (ompi_proc_t*)ompi_list_get_next(proc)) {
|
2004-02-13 16:56:55 +03:00
|
|
|
OBJ_RETAIN(proc);
|
|
|
|
procs[count++] = proc;
|
|
|
|
}
|
2004-06-25 01:09:55 +04:00
|
|
|
THREAD_UNLOCK(&ompi_proc_lock);
|
2004-02-13 16:56:55 +03:00
|
|
|
*size = count;
|
|
|
|
return procs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t** ompi_proc_self(size_t* size)
|
2004-02-13 16:56:55 +03:00
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t **procs = malloc(sizeof(ompi_proc_t*));
|
2004-02-13 16:56:55 +03:00
|
|
|
if(NULL == procs)
|
|
|
|
return NULL;
|
2004-06-07 19:33:53 +04:00
|
|
|
OBJ_RETAIN(ompi_proc_local_proc);
|
|
|
|
*procs = ompi_proc_local_proc;
|
2004-02-13 16:56:55 +03:00
|
|
|
*size = 1;
|
|
|
|
return procs;
|
|
|
|
}
|
|
|
|
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t * ompi_proc_find ( ompi_job_handle_t jobid, uint32_t vpid )
|
2004-05-18 01:28:32 +04:00
|
|
|
{
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t *proc;
|
2004-05-18 01:28:32 +04:00
|
|
|
|
|
|
|
/* return the proc-struct which matches this jobid+process id */
|
2004-06-25 01:09:55 +04:00
|
|
|
THREAD_LOCK(&ompi_proc_lock);
|
2004-06-07 19:33:53 +04:00
|
|
|
for(proc = (ompi_proc_t*)ompi_list_get_first(&ompi_proc_list);
|
|
|
|
proc != (ompi_proc_t*)ompi_list_get_end(&ompi_proc_list);
|
|
|
|
proc = (ompi_proc_t*)ompi_list_get_next(proc)) {
|
2004-05-18 01:28:32 +04:00
|
|
|
if( (strcmp(proc->proc_job,jobid) == 0) &&
|
|
|
|
(proc->proc_vpid == vpid ) )
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-06-25 01:09:55 +04:00
|
|
|
THREAD_UNLOCK(&ompi_proc_lock);
|
2004-05-18 01:28:32 +04:00
|
|
|
return proc;
|
|
|
|
}
|