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-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-06-07 19:33:53 +04:00
|
|
|
ompi_proc_t *proc;
|
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
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-06-25 01:39:08 +04:00
|
|
|
OMPI_THREAD_UNLOCK(&ompi_proc_lock);
|
2004-05-18 01:28:32 +04:00
|
|
|
return proc;
|
|
|
|
}
|
2004-07-01 18:49:54 +04:00
|
|
|
|
2004-08-04 21:05:22 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** The functions in this chapter are at the moment purely for
|
|
|
|
** homogeneous environments. Support for heterogeneous environments
|
|
|
|
** to follow as soon as the datatype engine supports heterogeneous envs.
|
|
|
|
** I just wanted to avoid duplicating data conversion code here...
|
|
|
|
*/
|
|
|
|
int ompi_proc_get_namebuf_by_proc ( ompi_proc_t **proclist, int proclistsize,
|
2004-08-05 20:27:13 +04:00
|
|
|
char **namebuf, int *namebuflen )
|
2004-08-04 21:05:22 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ompi_process_name_t *nbuf=NULL;
|
|
|
|
|
2004-08-05 20:27:13 +04:00
|
|
|
nbuf = (ompi_process_name_t *) calloc (proclistsize, sizeof(ompi_process_name_t));
|
2004-08-04 21:05:22 +04:00
|
|
|
if ( NULL == nbuf ) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPI_THREAD_LOCK(&ompi_proc_lock);
|
|
|
|
for (i=0; i<proclistsize; i++) {
|
|
|
|
nbuf[i] = proclist[i]->proc_name;
|
|
|
|
}
|
|
|
|
OMPI_THREAD_UNLOCK(&ompi_proc_lock);
|
|
|
|
|
|
|
|
*namebuf = (char *)nbuf;
|
|
|
|
*namebuflen = (proclistsize * sizeof(ompi_process_name_t));
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ompi_proc_namebuf_returnbuf ( char *namebuf )
|
|
|
|
{
|
|
|
|
if ( NULL != namebuf ) {
|
|
|
|
free (namebuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-05 20:27:13 +04:00
|
|
|
int ompi_proc_get_proclist (char *namebuf, int namebuflen,
|
2004-08-04 21:05:22 +04:00
|
|
|
int proclistsize, ompi_proc_t ***proclist)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ompi_proc_t **plist=NULL;
|
|
|
|
ompi_process_name_t *nlist= (ompi_process_name_t *) namebuf;
|
|
|
|
|
|
|
|
plist = (ompi_proc_t **) calloc ( proclistsize, sizeof (ompi_proc_t *));
|
|
|
|
if ( NULL == plist ) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i=0; i<proclistsize; i++ ){
|
|
|
|
plist[i] = ompi_proc_find ( &(nlist[i]));
|
|
|
|
if ( NULL == plist[i] ) {
|
|
|
|
/* to do: look the process information for this name up */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*proclist = plist;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These two functions are at the moment trivial */
|
|
|
|
int ompi_proc_get_namebuf_by_name ( ompi_process_name_t **namelist, int namelistsize,
|
2004-08-05 20:27:13 +04:00
|
|
|
char **namebuf, int *namebuflen )
|
2004-08-04 21:05:22 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ompi_process_name_t *nbuf=NULL;
|
|
|
|
|
|
|
|
nbuf = ( ompi_process_name_t *) calloc (namelistsize, sizeof(ompi_process_name_t));
|
|
|
|
if ( NULL == nbuf ) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<namelistsize; i++) {
|
|
|
|
nbuf[i] = *(namelist[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
*namebuf = (char *)nbuf;
|
|
|
|
*namebuflen = (namelistsize * sizeof(ompi_process_name_t));
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-08-05 20:27:13 +04:00
|
|
|
int ompi_proc_get_namelist ( char *namebuf, int namebuflen,
|
2004-08-04 21:05:22 +04:00
|
|
|
int namelistsize, ompi_process_name_t ***namelist )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ompi_proc_t *proc;
|
|
|
|
ompi_process_name_t **plist=NULL;
|
|
|
|
ompi_process_name_t *nlist= (ompi_process_name_t *) namebuf;
|
|
|
|
|
|
|
|
plist = (ompi_process_name_t**)calloc(namelistsize,sizeof(ompi_process_name_t *));
|
|
|
|
if ( NULL == plist ) {
|
|
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( i=0; i<namelistsize; i++ ){
|
|
|
|
proc = ompi_proc_find ( &(nlist[i]));
|
|
|
|
if ( NULL == plist[i] ) {
|
|
|
|
/* to do: look the process information for this name up */
|
|
|
|
}
|
|
|
|
plist[i] = &(proc->proc_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|