2004-07-08 18:48:34 +04:00
|
|
|
/*
|
|
|
|
* $HEADER
|
|
|
|
*/
|
|
|
|
|
2004-08-19 03:24:27 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "ompi_config.h"
|
|
|
|
#endif
|
|
|
|
|
2004-02-13 16:56:55 +03:00
|
|
|
#include <string.h>
|
2004-07-08 18:48:34 +04:00
|
|
|
|
2004-03-17 21:45:16 +03:00
|
|
|
#include "threads/mutex.h"
|
|
|
|
#include "util/output.h"
|
|
|
|
#include "proc/proc.h"
|
2004-08-18 02:24:17 +04:00
|
|
|
#include "mca/pcmclient/pcmclient.h"
|
|
|
|
#include "mca/pcmclient/base/base.h"
|
2004-07-01 18:49:54 +04:00
|
|
|
#include "mca/oob/oob.h"
|
2004-07-08 18:48:34 +04:00
|
|
|
#include "mca/ns/base/base.h"
|
2004-10-01 00:54:26 +04:00
|
|
|
#include "mca/pml/pml.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-08-19 03:24:27 +04:00
|
|
|
if(ompi_atomic_fetch_and_set_int(&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_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:39:08 +04:00
|
|
|
OMPI_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:39:08 +04:00
|
|
|
OMPI_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:39:08 +04:00
|
|
|
OMPI_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:39:08 +04:00
|
|
|
OMPI_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
|
|
|
{
|
2004-07-01 18:49:54 +04:00
|
|
|
ompi_process_name_t *peers;
|
|
|
|
ompi_process_name_t *self;
|
|
|
|
size_t i, npeers;
|
2004-02-13 16:56:55 +03:00
|
|
|
int rc;
|
|
|
|
|
2004-08-18 02:24:17 +04:00
|
|
|
if(OMPI_SUCCESS != (rc = mca_pcmclient.pcmclient_get_peers(&peers,
|
|
|
|
&npeers))) {
|
2004-07-01 18:49:54 +04:00
|
|
|
ompi_output(0, "ompi_proc_init: mca_pcm.pcm_peers failed with errno=%d", rc);
|
2004-02-13 16:56:55 +03:00
|
|
|
return rc;
|
|
|
|
}
|
2004-08-18 02:24:17 +04:00
|
|
|
if(NULL == (self = mca_pcmclient.pcmclient_get_self())) {
|
2004-07-01 18:49:54 +04:00
|
|
|
ompi_output(0, "ompi_proc_init: mca_pcm.pcm_self failed with errno=%d", rc);
|
2004-02-13 16:56:55 +03:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2004-07-01 18:49:54 +04:00
|
|
|
for(i=0; i<npeers; i++) {
|
2004-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t *proc = OBJ_NEW(ompi_proc_t);
|
2004-07-01 18:49:54 +04:00
|
|
|
proc->proc_name = peers[i];
|
|
|
|
if( peers + i == self ) {
|
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
|
|
|
}
|
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;
|
2004-02-13 16:56:55 +03:00
|
|
|
size_t count = 0;
|
|
|
|
|
|
|
|
if(NULL == procs)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* return only the procs that match this jobid */
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_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-07-01 18:49:54 +04:00
|
|
|
/* TSW - FIX */
|
|
|
|
procs[count++] = proc;
|
2004-02-13 16:56:55 +03:00
|
|
|
}
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_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:39:08 +04:00
|
|
|
OMPI_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:39:08 +04:00
|
|
|
OMPI_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-07-01 18:49:54 +04:00
|
|
|
ompi_proc_t * ompi_proc_find ( const ompi_process_name_t * name )
|
2004-05-18 01:28:32 +04:00
|
|
|
{
|
2004-09-17 14:10:24 +04:00
|
|
|
ompi_proc_t *proc, *rproc=NULL;
|
2004-07-08 18:48:34 +04:00
|
|
|
ompi_ns_cmp_bitmask_t mask;
|
2004-05-18 01:28:32 +04:00
|
|
|
|
|
|
|
/* return the proc-struct which matches this jobid+process id */
|
2004-07-08 18:48:34 +04:00
|
|
|
|
|
|
|
mask = OMPI_NS_CMP_CELLID | OMPI_NS_CMP_JOBID | OMPI_NS_CMP_VPID;
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_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-07-08 18:48:34 +04:00
|
|
|
if (0 == ompi_name_server.compare(mask, &proc->proc_name, name))
|
2004-05-18 01:28:32 +04:00
|
|
|
{
|
2004-09-17 14:10:24 +04:00
|
|
|
rproc = proc;
|
2004-05-18 01:28:32 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&ompi_proc_lock);
|
2004-09-17 14:10:24 +04:00
|
|
|
return rproc;
|
2004-05-18 01:28:32 +04:00
|
|
|
}
|
2004-07-01 18:49:54 +04:00
|
|
|
|
2004-08-04 21:05:22 +04:00
|
|
|
|
2004-09-17 14:10:24 +04:00
|
|
|
ompi_proc_t * ompi_proc_find_and_add ( const ompi_process_name_t * name )
|
|
|
|
{
|
|
|
|
ompi_proc_t *proc, *rproc=NULL;
|
|
|
|
ompi_ns_cmp_bitmask_t mask;
|
|
|
|
|
|
|
|
/* return the proc-struct which matches this jobid+process id */
|
|
|
|
mask = OMPI_NS_CMP_CELLID | OMPI_NS_CMP_JOBID | OMPI_NS_CMP_VPID;
|
|
|
|
OMPI_THREAD_LOCK(&ompi_proc_lock);
|
|
|
|
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)) {
|
|
|
|
if (0 == ompi_name_server.compare(mask, &proc->proc_name, name))
|
|
|
|
{
|
2004-10-01 00:54:26 +04:00
|
|
|
rproc = proc;
|
2004-09-17 14:10:24 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-10-01 00:54:26 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&ompi_proc_lock);
|
2004-09-17 14:10:24 +04:00
|
|
|
|
|
|
|
if ( NULL == rproc ) {
|
2004-10-01 00:54:26 +04:00
|
|
|
ompi_proc_t *tproc = OBJ_NEW(ompi_proc_t);
|
|
|
|
rproc = tproc;
|
|
|
|
rproc->proc_name = *name;
|
|
|
|
|
|
|
|
/* downcall into pml to notify ptls of new proc */
|
|
|
|
mca_pml.pml_add_procs(&rproc,1);
|
2004-09-17 14:10:24 +04:00
|
|
|
}
|
|
|
|
return rproc;
|
|
|
|
}
|
|
|
|
|
2004-09-16 14:07:14 +04:00
|
|
|
int ompi_proc_get_namebuf ( ompi_proc_t **proclist, int proclistsize,
|
|
|
|
ompi_buffer_t buf)
|
2004-08-04 21:05:22 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2004-09-16 14:07:14 +04:00
|
|
|
/* buf has to be initiated in the calling function */
|
2004-08-04 21:05:22 +04:00
|
|
|
|
|
|
|
OMPI_THREAD_LOCK(&ompi_proc_lock);
|
|
|
|
for (i=0; i<proclistsize; i++) {
|
2004-09-16 14:07:14 +04:00
|
|
|
ompi_pack(buf, &(proclist[i]->proc_name), 1, OMPI_NAME);
|
2004-08-04 21:05:22 +04:00
|
|
|
}
|
|
|
|
OMPI_THREAD_UNLOCK(&ompi_proc_lock);
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-16 14:07:14 +04:00
|
|
|
int ompi_proc_get_proclist (ompi_buffer_t buf, int proclistsize, ompi_proc_t ***proclist)
|
2004-08-04 21:05:22 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ompi_proc_t **plist=NULL;
|
2004-09-16 14:07:14 +04:00
|
|
|
ompi_process_name_t name;
|
|
|
|
|
|
|
|
/* do not free plist *ever*, since it is used in the remote group structure
|
|
|
|
of a communicator */
|
|
|
|
plist = (ompi_proc_t **) calloc (proclistsize, sizeof (ompi_proc_t *));
|
2004-08-04 21:05:22 +04:00
|
|
|
if ( NULL == plist ) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i=0; i<proclistsize; i++ ){
|
2004-09-16 14:07:14 +04:00
|
|
|
ompi_unpack(buf, &name, 1, OMPI_NAME);
|
2004-09-17 14:10:24 +04:00
|
|
|
plist[i] = ompi_proc_find_and_add ( &name);
|
2004-08-04 21:05:22 +04:00
|
|
|
}
|
|
|
|
*proclist = plist;
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|