2005-05-24 02:06:50 +04:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
2006-08-24 20:38:08 +04:00
|
|
|
* Copyright (c) 2004-2006 The University of Tennessee and The University
|
2005-11-05 22:57:48 +03:00
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2005-05-24 02:06:50 +04:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2005-07-04 02:45:48 +04:00
|
|
|
#include "opal/threads/mutex.h"
|
2005-09-13 00:22:59 +04:00
|
|
|
#include "ompi/datatype/convertor.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal/sys/atomic.h"
|
2005-07-04 03:31:27 +04:00
|
|
|
#include "opal/util/output.h"
|
2005-07-04 05:36:20 +04:00
|
|
|
#include "opal/util/if.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "orte/util/proc_info.h"
|
2005-07-04 06:16:57 +04:00
|
|
|
#include "opal/util/printf.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "orte/util/sys_info.h"
|
2005-09-13 00:22:59 +04:00
|
|
|
#include "ompi/class/ompi_fifo.h"
|
|
|
|
#include "ompi/class/ompi_free_list.h"
|
|
|
|
#include "ompi/mca/pml/pml.h"
|
|
|
|
#include "ompi/mca/btl/btl.h"
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "ompi/mca/mpool/base/base.h"
|
|
|
|
#include "ompi/mca/common/sm/common_sm_mmap.h"
|
2005-06-30 09:50:55 +04:00
|
|
|
#include "btl_sm.h"
|
|
|
|
#include "btl_sm_endpoint.h"
|
|
|
|
#include "btl_sm_frag.h"
|
2005-07-28 20:25:09 +04:00
|
|
|
#include "btl_sm_fifo.h"
|
2005-09-13 00:22:59 +04:00
|
|
|
#include "ompi/proc/proc.h"
|
2005-05-24 02:06:50 +04:00
|
|
|
|
2005-11-13 01:32:09 +03:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Note that there are effectively two versions of the btl sm module
|
|
|
|
* -- one that assumes that the base address of the shared memory
|
|
|
|
* segment is the same between pairs of processes (i.e., mmap()
|
|
|
|
* returned the same virtual address for the same segment in both
|
|
|
|
* processes), and one that assumes that the base addresses are
|
|
|
|
* different.
|
|
|
|
*
|
|
|
|
* In the former, no translation is necessary -- all pointers can be
|
|
|
|
* stored directly as-is and used in both processes.
|
|
|
|
*
|
|
|
|
* In the latter, we calculate the difference between the base virtual
|
|
|
|
* address of the two process' shared memory segments and cache it.
|
|
|
|
* This difference is used to access memory and pointers written by
|
|
|
|
* the other process.
|
|
|
|
*
|
|
|
|
* Specifically, a good portion of this btl is implemented in the
|
|
|
|
* ompi_fifo_t and ompi_circular_buffer_t classes. These classes
|
|
|
|
* *always* store absolute virtual addresses in their data structures.
|
|
|
|
* The virtual addresses are always meaningful in the *sender's*
|
|
|
|
* process space. If the base address is the same in both processes,
|
|
|
|
* then we get the happy side effect that the virtual addresses are
|
|
|
|
* also valid in the receiver's process space, and therefore no
|
|
|
|
* address translation needs to be done when the reader accesses the
|
|
|
|
* data.
|
|
|
|
*
|
|
|
|
* However, in the case where the base addresses are different, the
|
|
|
|
* receiver must translate every pointer address in the ompi_fifo_t
|
|
|
|
* and ompi_circular_buffer_t data structures (even when writing back
|
|
|
|
* to those data structures, such as updating a head or tail pointer).
|
|
|
|
*
|
|
|
|
* In short, we use a "receiver makes right" scheme, and in some
|
|
|
|
* cases, the receiver doesn't have to do anything.
|
|
|
|
*/
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_t mca_btl_sm[2] = {
|
2005-05-24 02:06:50 +04:00
|
|
|
{
|
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
&mca_btl_sm_component.super,
|
|
|
|
0, /* btl_eager_limit */
|
|
|
|
0, /* btl_min_send_size */
|
|
|
|
0, /* btl_max_send_size */
|
|
|
|
0, /* btl_min_rdma_size */
|
|
|
|
0, /* btl_max_rdma_size */
|
|
|
|
0, /* btl_exclusivity */
|
|
|
|
0, /* btl_latency */
|
|
|
|
0, /* btl_bandwidth */
|
|
|
|
0, /* btl flags */
|
|
|
|
mca_btl_sm_add_procs_same_base_addr,
|
|
|
|
mca_btl_sm_del_procs,
|
|
|
|
mca_btl_sm_register,
|
|
|
|
mca_btl_sm_finalize,
|
|
|
|
mca_btl_sm_alloc,
|
|
|
|
mca_btl_sm_free,
|
|
|
|
mca_btl_sm_prepare_src,
|
2005-06-01 18:34:22 +04:00
|
|
|
NULL,
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_send,
|
2005-05-24 02:06:50 +04:00
|
|
|
NULL, /* put */
|
2006-03-17 20:39:41 +03:00
|
|
|
NULL, /* get */
|
2006-08-18 02:02:01 +04:00
|
|
|
mca_btl_base_dump,
|
|
|
|
NULL, /* mpool */
|
2007-02-13 15:01:36 +03:00
|
|
|
mca_btl_sm_register_error_cb /* register error */
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
&mca_btl_sm_component.super,
|
|
|
|
0, /* btl_eager_limit */
|
|
|
|
0, /* btl_min_send_size */
|
|
|
|
0, /* btl_max_send_size */
|
|
|
|
0, /* btl_min_rdma_size */
|
|
|
|
0, /* btl_max_rdma_size */
|
|
|
|
0, /* btl_exclusivity */
|
|
|
|
0, /* btl_latency */
|
|
|
|
0, /* btl_bandwidth */
|
|
|
|
0, /* btl flags */
|
|
|
|
mca_btl_sm_add_procs,
|
|
|
|
mca_btl_sm_del_procs,
|
|
|
|
mca_btl_sm_register,
|
|
|
|
mca_btl_sm_finalize,
|
|
|
|
mca_btl_sm_alloc,
|
|
|
|
mca_btl_sm_free,
|
|
|
|
mca_btl_sm_prepare_src,
|
2005-06-01 18:34:22 +04:00
|
|
|
NULL,
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_send,
|
2006-03-17 20:39:41 +03:00
|
|
|
NULL, /* put function */
|
2005-05-24 02:06:50 +04:00
|
|
|
NULL, /* get function */
|
2006-08-18 02:02:01 +04:00
|
|
|
mca_btl_base_dump,
|
|
|
|
NULL, /* mpool */
|
2007-02-13 15:01:36 +03:00
|
|
|
mca_btl_sm_register_error_cb /* register error */
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
/* track information needed to synchronise a Shared Memory BTL module */
|
|
|
|
mca_btl_sm_module_resource_t mca_btl_sm_module_resource;
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_sm_add_procs_same_base_addr(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
2005-05-24 02:06:50 +04:00
|
|
|
size_t nprocs,
|
|
|
|
struct ompi_proc_t **procs,
|
2005-06-30 09:50:55 +04:00
|
|
|
struct mca_btl_base_endpoint_t **peers,
|
2005-05-24 02:06:50 +04:00
|
|
|
ompi_bitmap_t* reachability)
|
|
|
|
{
|
2006-10-20 23:28:12 +04:00
|
|
|
int return_code = OMPI_SUCCESS, cnt, len;
|
|
|
|
size_t i, j, size, n_to_allocate, length;
|
|
|
|
int32_t n_local_procs, proc;
|
2005-05-24 02:06:50 +04:00
|
|
|
ompi_proc_t* my_proc; /* pointer to caller's proc structure */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_t *btl_sm;
|
2005-05-24 02:06:50 +04:00
|
|
|
ompi_fifo_t *my_fifos;
|
|
|
|
ompi_fifo_t * volatile *fifo_tmp;
|
|
|
|
bool same_sm_base;
|
2006-10-20 07:57:44 +04:00
|
|
|
ptrdiff_t diff;
|
2005-05-24 02:06:50 +04:00
|
|
|
volatile char **tmp_ptr;
|
2005-11-12 17:04:46 +03:00
|
|
|
volatile int *tmp_int_ptr;
|
2007-02-01 20:18:35 +03:00
|
|
|
bool have_connected_peer = false;
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
/* initializion */
|
2006-10-20 23:28:12 +04:00
|
|
|
for( i = 0 ; i < nprocs ; i++ ) {
|
|
|
|
peers[i] = NULL;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
2005-06-30 09:50:55 +04:00
|
|
|
btl_sm=(mca_btl_sm_t *)btl;
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
/* allocate array to hold setup shared memory from all
|
|
|
|
* other procs */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_proc_connect=(int *) malloc(nprocs*sizeof(int));
|
|
|
|
if( NULL == mca_btl_sm_component.sm_proc_connect ){
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
2005-07-15 19:22:41 +04:00
|
|
|
/* initialize and sm_proc_connect*/
|
2006-10-20 23:28:12 +04:00
|
|
|
for( proc = 0 ; proc < (int32_t)nprocs ; proc++ ) {
|
|
|
|
mca_btl_sm_component.sm_proc_connect[proc] = 0;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get pointer to my proc structure */
|
|
|
|
my_proc=ompi_proc_local();
|
|
|
|
if( NULL == my_proc ) {
|
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get unique host identifier for each process in the list,
|
|
|
|
* and idetify procs that are on this host. Add procs on this
|
|
|
|
* host to shared memory reachbility list. Also, get number
|
|
|
|
* of local procs in the prcs list. */
|
|
|
|
n_local_procs=0;
|
2006-10-20 23:28:12 +04:00
|
|
|
for( proc=0 ; proc < (int32_t)nprocs; proc++ ) {
|
2005-07-15 19:22:41 +04:00
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS == 1
|
|
|
|
char path[PATH_MAX];
|
|
|
|
#endif
|
|
|
|
struct mca_btl_base_endpoint_t *peer;
|
|
|
|
|
|
|
|
/* check to see if this proc can be reached via shmem (i.e.,
|
|
|
|
if they're on my local host and in my job) */
|
2007-02-01 20:18:35 +03:00
|
|
|
if (procs[proc]->proc_name.jobid != my_proc->proc_name.jobid ||
|
2005-07-15 19:22:41 +04:00
|
|
|
0 == (procs[proc]->proc_flags & OMPI_PROC_FLAG_LOCAL)) {
|
2005-05-24 02:06:50 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-07-15 19:22:41 +04:00
|
|
|
/* If we got here, the proc is reachable via sm. So
|
|
|
|
initialize the peers information */
|
2007-02-01 20:18:35 +03:00
|
|
|
|
|
|
|
/* check to see if this is me */
|
|
|
|
if( my_proc == procs[proc] ) {
|
|
|
|
mca_btl_sm_component.my_smp_rank = n_local_procs;
|
|
|
|
} else {
|
|
|
|
/* we have someone to talk to */
|
|
|
|
have_connected_peer = true;
|
|
|
|
}
|
|
|
|
|
2006-08-24 20:38:08 +04:00
|
|
|
peer = peers[proc] = (struct mca_btl_base_endpoint_t*)malloc(sizeof(struct mca_btl_base_endpoint_t));
|
2005-07-15 19:22:41 +04:00
|
|
|
if( NULL == peer ){
|
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
2005-05-24 02:06:50 +04:00
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2005-07-15 19:22:41 +04:00
|
|
|
peer->peer_smp_rank=n_local_procs+
|
|
|
|
mca_btl_sm_component.num_smp_procs;
|
|
|
|
|
2005-05-24 02:06:50 +04:00
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS == 1
|
2006-08-24 20:38:08 +04:00
|
|
|
sprintf(path, "%s"OPAL_PATH_SEP"sm_fifo.%lu", orte_process_info.job_session_dir,
|
2005-09-12 00:55:22 +04:00
|
|
|
(unsigned long)procs[proc]->proc_name.vpid);
|
2005-07-15 19:22:41 +04:00
|
|
|
peer->fifo_fd = open(path, O_WRONLY);
|
|
|
|
if(peer->fifo_fd < 0) {
|
|
|
|
opal_output(0, "mca_btl_sm_add_procs: open(%s) failed with errno=%d\n", path, errno);
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2005-05-24 02:06:50 +04:00
|
|
|
#endif
|
2005-07-15 19:22:41 +04:00
|
|
|
n_local_procs++;
|
|
|
|
mca_btl_sm_component.sm_proc_connect[proc]=SM_CONNECTED;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
2005-07-15 19:22:41 +04:00
|
|
|
|
2007-02-01 20:18:35 +03:00
|
|
|
/* jump out if there's not someone we can talk to */
|
|
|
|
if (!have_connected_peer) {
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code = OMPI_SUCCESS;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lookup shared memory pool */
|
2005-06-30 09:50:55 +04:00
|
|
|
if(NULL == mca_btl_sm_component.sm_mpool) {
|
|
|
|
mca_btl_sm_component.sm_mpool =
|
2005-07-16 00:01:35 +04:00
|
|
|
mca_mpool_base_module_lookup(mca_btl_sm_component.sm_mpool_name);
|
|
|
|
if (NULL == mca_btl_sm_component.sm_mpool) {
|
|
|
|
mca_btl_sm_component.sm_mpool =
|
|
|
|
mca_mpool_base_module_create(mca_btl_sm_component.sm_mpool_name,btl,NULL);
|
|
|
|
}
|
2005-06-21 21:18:28 +04:00
|
|
|
|
2005-05-24 02:06:50 +04:00
|
|
|
/* Sanity check to ensure that we found it */
|
2005-06-30 09:50:55 +04:00
|
|
|
if (NULL == mca_btl_sm_component.sm_mpool) {
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code = OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_mpool_base =
|
2006-08-24 20:38:08 +04:00
|
|
|
mca_btl_sm_component.sm_mpool->mpool_base((mca_mpool_base_module_t*)mca_btl_sm_component.sm_mpool_base);
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure that my_smp_rank has been defined */
|
2005-06-30 09:50:55 +04:00
|
|
|
if( 0xFFFFFFFF == mca_btl_sm_component.my_smp_rank ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code=OMPI_ERROR;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* see if need to allocate space for extra procs */
|
2005-06-30 09:50:55 +04:00
|
|
|
if( 0 > mca_btl_sm_component.sm_max_procs ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
/* no limit */
|
2005-06-30 09:50:55 +04:00
|
|
|
if( 0 <= mca_btl_sm_component.sm_extra_procs ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
/* limit */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_max_procs=n_local_procs+
|
|
|
|
mca_btl_sm_component.sm_extra_procs;
|
2005-05-24 02:06:50 +04:00
|
|
|
} else {
|
|
|
|
/* no limit */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_max_procs=2*n_local_procs;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
}
|
2005-06-30 09:50:55 +04:00
|
|
|
n_to_allocate=mca_btl_sm_component.sm_max_procs;
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
/* make sure n_to_allocate is greater than 0 */
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
if ( !mca_btl_sm[0].btl_inited ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
/* set the shared memory offset */
|
2006-10-20 23:28:12 +04:00
|
|
|
mca_btl_sm_component.sm_offset=(ptrdiff_t*)
|
|
|
|
malloc(n_to_allocate*sizeof(ptrdiff_t));
|
2005-06-30 09:50:55 +04:00
|
|
|
if(NULL == mca_btl_sm_component.sm_offset ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a list of peers */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_peers=(struct mca_btl_base_endpoint_t**)
|
|
|
|
malloc(n_to_allocate*sizeof(struct mca_btl_base_endpoint_t*));
|
|
|
|
if(NULL == mca_btl_sm_component.sm_peers ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set local proc's smp rank in the peers structure for
|
|
|
|
* rapid access */
|
2006-10-20 23:28:12 +04:00
|
|
|
for( proc=0 ; proc < (int32_t)nprocs; proc++ ) {
|
2005-06-30 09:50:55 +04:00
|
|
|
struct mca_btl_base_endpoint_t* peer = peers[proc];
|
2005-05-24 02:06:50 +04:00
|
|
|
if(NULL != peer) {
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_peers[peer->peer_smp_rank] = peer;
|
|
|
|
peer->my_smp_rank=mca_btl_sm_component.my_smp_rank;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
/* Allocate Shared Memory BTL process coordination
|
2005-05-24 02:06:50 +04:00
|
|
|
* data structure. This will reside in shared memory */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create backing file - only first time through
|
|
|
|
*/
|
2005-06-30 09:50:55 +04:00
|
|
|
if ( !mca_btl_sm[0].btl_inited ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
/* set file name */
|
2005-06-30 09:50:55 +04:00
|
|
|
len=asprintf(&(mca_btl_sm_component.sm_resouce_ctl_file),
|
2006-08-24 20:38:08 +04:00
|
|
|
"%s"OPAL_PATH_SEP"shared_mem_btl_module.%s",orte_process_info.job_session_dir,
|
2005-05-24 02:06:50 +04:00
|
|
|
orte_system_info.nodename);
|
|
|
|
if( 0 > len ) {
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
2005-08-09 01:38:27 +04:00
|
|
|
/* Pass in a data segment alignment of 0 to get no data
|
|
|
|
segment (only the shared control structure */
|
|
|
|
size = sizeof(mca_btl_sm_module_resource_t);
|
2005-06-30 09:50:55 +04:00
|
|
|
if(NULL==(mca_btl_sm_component.mmap_file=mca_common_sm_mmap_init(size,
|
|
|
|
mca_btl_sm_component.sm_resouce_ctl_file,
|
2005-08-09 01:38:27 +04:00
|
|
|
sizeof(mca_btl_sm_module_resource_t), 0)))
|
2005-05-24 02:06:50 +04:00
|
|
|
{
|
2007-02-01 20:51:43 +03:00
|
|
|
opal_output(0, "mca_btl_sm_add_procs: unable to create shared memory BTL coordinating strucure :: size %lu \n",
|
|
|
|
(unsigned long)size);
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code=OMPI_ERROR;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the pointer to the shared memory control structure */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_ctl_header=(mca_btl_sm_module_resource_t *)
|
|
|
|
mca_btl_sm_component.mmap_file->map_seg;
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
|
|
|
|
/* Allocate a fixed size pointer array for the 2-D Shared memory queues.
|
|
|
|
* Excess slots will be allocated for future growth. One could
|
|
|
|
* make this array growable, but then one would need to uses mutexes
|
|
|
|
* for any access to these queues to ensure data consistancy when
|
|
|
|
* the array is grown */
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
if(0 == mca_btl_sm_component.my_smp_rank ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
/* allocate ompi_fifo_t strucutes for each fifo of the queue
|
|
|
|
* pairs - one per pair of local processes */
|
|
|
|
/* check to make sure number of local procs is within the
|
|
|
|
* specified limits */
|
2005-06-30 09:50:55 +04:00
|
|
|
if( ( 0 < mca_btl_sm_component.sm_max_procs ) &&
|
|
|
|
( n_local_procs > mca_btl_sm_component.sm_max_procs) ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code=OMPI_ERROR;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate array of ompi_fifo_t* elements -
|
|
|
|
* offset relative to base segement is stored, so that
|
|
|
|
* this can be used by other procs */
|
2006-08-24 20:38:08 +04:00
|
|
|
mca_btl_sm_component.sm_ctl_header->fifo= (volatile ompi_fifo_t**)
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_mpool->mpool_alloc
|
|
|
|
(mca_btl_sm_component.sm_mpool, n_to_allocate*sizeof(ompi_fifo_t *),
|
2005-09-13 02:28:23 +04:00
|
|
|
CACHE_LINE_SIZE, 0, NULL);
|
2005-06-30 09:50:55 +04:00
|
|
|
if ( NULL == mca_btl_sm_component.sm_ctl_header->fifo ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
/* initiazlize the pointer array */
|
|
|
|
for(i=0 ; i < n_to_allocate ; i++ ) {
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_ctl_header->fifo[i]=NULL;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate and initialize the array to hold the virtual address
|
|
|
|
* of the shared memory base */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_ctl_header->segment_header.
|
2005-05-24 02:06:50 +04:00
|
|
|
base_shared_mem_segment = ( volatile char **)
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_mpool->mpool_alloc
|
2005-09-13 02:28:23 +04:00
|
|
|
(mca_btl_sm_component.sm_mpool, n_to_allocate*sizeof(char *), CACHE_LINE_SIZE, 0, NULL);
|
2005-06-30 09:50:55 +04:00
|
|
|
if ( NULL == mca_btl_sm_component.sm_ctl_header->segment_header.
|
2005-05-24 02:06:50 +04:00
|
|
|
base_shared_mem_segment ) {
|
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
/* initialize the pointer array */
|
|
|
|
for(i=0 ; i < n_to_allocate ; i++ ) {
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_ctl_header->segment_header.
|
2005-05-24 02:06:50 +04:00
|
|
|
base_shared_mem_segment[i]=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate and initialize the array of flags indicating
|
|
|
|
* when the virtual address of the shared memory address
|
|
|
|
* has been set */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_ctl_header->segment_header.
|
2005-05-24 02:06:50 +04:00
|
|
|
base_shared_mem_flags = ( int *)
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_mpool->mpool_alloc
|
2005-09-13 02:28:23 +04:00
|
|
|
(mca_btl_sm_component.sm_mpool, n_to_allocate*sizeof(int), CACHE_LINE_SIZE, 0, NULL);
|
2005-06-30 09:50:55 +04:00
|
|
|
if ( NULL == mca_btl_sm_component.sm_ctl_header->segment_header.
|
2005-05-24 02:06:50 +04:00
|
|
|
base_shared_mem_flags ) {
|
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
for(i=0 ; i < n_to_allocate ; i++ ) {
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_ctl_header->segment_header.
|
2005-05-24 02:06:50 +04:00
|
|
|
base_shared_mem_flags[i]=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the addresses to be a relative, so that
|
|
|
|
* they can be used by other procs */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_ctl_header->fifo=
|
2005-05-24 02:06:50 +04:00
|
|
|
(volatile ompi_fifo_t **)
|
2005-06-30 09:50:55 +04:00
|
|
|
( (char *)(mca_btl_sm_component.sm_ctl_header->fifo)-
|
|
|
|
(char *)(mca_btl_sm_component.sm_mpool->mpool_base(mca_btl_sm_component.sm_mpool)) );
|
2005-05-24 02:06:50 +04:00
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_ctl_header->segment_header.
|
2005-05-24 02:06:50 +04:00
|
|
|
base_shared_mem_segment=( volatile char **)
|
2005-06-30 09:50:55 +04:00
|
|
|
( (char *)(mca_btl_sm_component.sm_ctl_header->
|
2005-05-24 02:06:50 +04:00
|
|
|
segment_header.base_shared_mem_segment) -
|
2005-06-30 09:50:55 +04:00
|
|
|
(char *)(mca_btl_sm_component.sm_mpool->mpool_base(mca_btl_sm_component.sm_mpool)) );
|
2005-05-24 02:06:50 +04:00
|
|
|
|
2005-11-12 17:04:46 +03:00
|
|
|
mca_btl_sm_component.sm_ctl_header->segment_header.
|
|
|
|
base_shared_mem_flags = (volatile int *)
|
|
|
|
( ((char *) mca_btl_sm_component.sm_ctl_header->
|
|
|
|
segment_header.base_shared_mem_flags) -
|
|
|
|
(char *) (mca_btl_sm_component.sm_mpool_base));
|
|
|
|
|
2005-05-24 02:06:50 +04:00
|
|
|
/* allow other procs to use this shared memory map */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.mmap_file->map_seg->seg_inited=true;
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
/* memory barrier to ensure this flag is set before other
|
|
|
|
* flags are set */
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_mb();
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: Need to make sure that proc 0 initializes control
|
|
|
|
* structures before any of the other procs can progress */
|
2005-06-30 09:50:55 +04:00
|
|
|
if( 0 != mca_btl_sm_component.my_smp_rank )
|
2005-05-24 02:06:50 +04:00
|
|
|
{
|
|
|
|
/* spin unitl local proc 0 initializes the segment */
|
2005-10-19 04:56:14 +04:00
|
|
|
while(!mca_btl_sm_component.mmap_file->map_seg->seg_inited) {
|
|
|
|
opal_progress();
|
|
|
|
}
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set the base of the shared memory segment, and flag
|
|
|
|
* indicating that it is set */
|
|
|
|
tmp_ptr=(volatile char **)
|
2005-06-30 09:50:55 +04:00
|
|
|
( (char *)(mca_btl_sm_component.sm_ctl_header->segment_header.
|
2005-05-24 02:06:50 +04:00
|
|
|
base_shared_mem_segment) +
|
2005-06-30 09:50:55 +04:00
|
|
|
(long )(mca_btl_sm_component.sm_mpool->mpool_base(mca_btl_sm_component.sm_mpool)) );
|
2006-08-24 20:38:08 +04:00
|
|
|
tmp_ptr[mca_btl_sm_component.my_smp_rank]=(char*)
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_mpool->mpool_base(mca_btl_sm_component.sm_mpool);
|
2005-05-24 02:06:50 +04:00
|
|
|
/* memory barrier to ensure this flag is set before other
|
|
|
|
* flags are set */
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_mb();
|
2005-05-24 02:06:50 +04:00
|
|
|
|
2006-08-24 20:38:08 +04:00
|
|
|
/* Set my flag to 1 (convert from relative address first) */
|
2005-11-12 17:04:46 +03:00
|
|
|
tmp_int_ptr=(volatile int *)
|
|
|
|
( ((char *) mca_btl_sm_component.sm_ctl_header->segment_header.
|
|
|
|
base_shared_mem_flags) +
|
|
|
|
((long) mca_btl_sm_component.sm_mpool_base));
|
2006-08-24 20:38:08 +04:00
|
|
|
tmp_int_ptr[mca_btl_sm_component.my_smp_rank]=1;
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize the array of fifo's "owned" by this process
|
|
|
|
* The virtual addresses are valid only in the sender's
|
|
|
|
* address space - unless the base of the shared memory
|
|
|
|
* segment is mapped at the same location in the reader's
|
|
|
|
* virtual address space.
|
|
|
|
*/
|
|
|
|
my_fifos=( ompi_fifo_t *)
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_mpool->mpool_alloc
|
2005-09-13 02:28:23 +04:00
|
|
|
(mca_btl_sm_component.sm_mpool, n_to_allocate*sizeof(ompi_fifo_t), CACHE_LINE_SIZE, 0, NULL);
|
2005-05-24 02:06:50 +04:00
|
|
|
if ( NULL == my_fifos ) {
|
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( j=0 ; j < n_to_allocate ; j++ ) {
|
2006-08-24 20:38:08 +04:00
|
|
|
my_fifos[j].head = (ompi_cb_fifo_wrapper_t*)OMPI_CB_FREE;
|
|
|
|
my_fifos[j].tail = (ompi_cb_fifo_wrapper_t*)OMPI_CB_FREE;
|
2005-07-04 01:38:51 +04:00
|
|
|
opal_atomic_unlock(&(my_fifos[j].head_lock));
|
|
|
|
opal_atomic_unlock(&(my_fifos[j].tail_lock));
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
fifo_tmp=(ompi_fifo_t * volatile *)
|
2005-06-30 09:50:55 +04:00
|
|
|
( (char *)(mca_btl_sm_component.sm_ctl_header->fifo) +
|
|
|
|
(long)(mca_btl_sm_component.sm_mpool->mpool_base(mca_btl_sm_component.sm_mpool)) );
|
|
|
|
fifo_tmp[mca_btl_sm_component.my_smp_rank]=my_fifos;
|
2005-09-19 20:28:25 +04:00
|
|
|
opal_atomic_mb();
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
/* cache the pointer to the 2d fifo array. These addresses
|
|
|
|
* are valid in the current process space */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.fifo=(ompi_fifo_t **)
|
2005-05-24 02:06:50 +04:00
|
|
|
malloc(sizeof(ompi_fifo_t *)*n_to_allocate);
|
2005-06-30 09:50:55 +04:00
|
|
|
if( NULL == mca_btl_sm_component.fifo ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code=OMPI_ERROR;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.fifo[mca_btl_sm_component.my_smp_rank]=my_fifos;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cache the pointers to the rest of the fifo arrays */
|
|
|
|
fifo_tmp=(ompi_fifo_t * volatile *)
|
2005-06-30 09:50:55 +04:00
|
|
|
( (char *)(mca_btl_sm_component.sm_ctl_header->fifo) +
|
|
|
|
(long)(mca_btl_sm_component.sm_mpool->mpool_base(mca_btl_sm_component.sm_mpool)) );
|
2005-11-13 01:32:09 +03:00
|
|
|
tmp_ptr=(volatile char **)
|
|
|
|
( (char *)mca_btl_sm_component.sm_ctl_header->
|
|
|
|
segment_header.base_shared_mem_segment +
|
|
|
|
(long)mca_btl_sm_component.sm_mpool->mpool_base(mca_btl_sm_component.sm_mpool));
|
2005-06-30 09:50:55 +04:00
|
|
|
for( j=mca_btl_sm_component.num_smp_procs ; j <
|
|
|
|
mca_btl_sm_component.num_smp_procs+n_local_procs ; j++ ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
/* spin until this element is allocated */
|
|
|
|
while ( NULL == fifo_tmp[j] )
|
2005-10-19 04:56:14 +04:00
|
|
|
{
|
|
|
|
opal_progress();
|
|
|
|
}
|
2005-05-24 02:06:50 +04:00
|
|
|
|
2005-11-13 01:32:09 +03:00
|
|
|
/* Calculate the difference as (my_base - their_base) */
|
|
|
|
diff = tmp_ptr[mca_btl_sm_component.my_smp_rank] - tmp_ptr[j];
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.fifo[j]=
|
2005-05-24 02:06:50 +04:00
|
|
|
( ompi_fifo_t *)( (char *)fifo_tmp[j]+diff);
|
2005-11-13 01:32:09 +03:00
|
|
|
mca_btl_sm_component.sm_offset[j] = diff;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize some of the free-lists */
|
2005-06-30 09:50:55 +04:00
|
|
|
if( !mca_btl_sm[0].btl_inited ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
/* some initialization happens only the first time this routine
|
2005-06-30 09:50:55 +04:00
|
|
|
* is called, i.e. when btl_inited is false */
|
2005-05-24 02:06:50 +04:00
|
|
|
|
2005-06-02 01:09:43 +04:00
|
|
|
/* initialize fragment descriptor free lists */
|
2005-05-24 02:06:50 +04:00
|
|
|
|
2005-06-02 01:09:43 +04:00
|
|
|
/* allocation will be for the fragment descriptor and payload buffer */
|
2005-06-30 09:50:55 +04:00
|
|
|
length=sizeof(mca_btl_sm_frag_t) + mca_btl_sm_component.eager_limit;
|
|
|
|
ompi_free_list_init(&mca_btl_sm_component.sm_frags1, length,
|
|
|
|
OBJ_CLASS(mca_btl_sm_frag1_t),
|
|
|
|
mca_btl_sm_component.sm_free_list_num,
|
|
|
|
mca_btl_sm_component.sm_free_list_max,
|
|
|
|
mca_btl_sm_component.sm_free_list_inc,
|
|
|
|
mca_btl_sm_component.sm_mpool); /* use shared-memory pool */
|
|
|
|
|
|
|
|
length=sizeof(mca_btl_sm_frag_t) + mca_btl_sm_component.max_frag_size;
|
|
|
|
ompi_free_list_init(&mca_btl_sm_component.sm_frags2, length,
|
|
|
|
OBJ_CLASS(mca_btl_sm_frag2_t),
|
|
|
|
mca_btl_sm_component.sm_free_list_num,
|
|
|
|
mca_btl_sm_component.sm_free_list_max,
|
|
|
|
mca_btl_sm_component.sm_free_list_inc,
|
|
|
|
mca_btl_sm_component.sm_mpool); /* use shared-memory pool */
|
|
|
|
|
|
|
|
/* set up mca_btl_sm_component.list_smp_procs_same_base_addr */
|
|
|
|
mca_btl_sm_component.list_smp_procs_same_base_addr=(int *)
|
|
|
|
malloc(mca_btl_sm_component.sm_max_procs*sizeof(int));
|
|
|
|
if( NULL == mca_btl_sm_component.list_smp_procs_same_base_addr ){
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
/* set up mca_btl_sm_component.list_smp_procs_different_base_addr */
|
|
|
|
mca_btl_sm_component.list_smp_procs_different_base_addr=(int *)
|
|
|
|
malloc(mca_btl_sm_component.sm_max_procs*sizeof(int));
|
|
|
|
if( NULL == mca_btl_sm_component.list_smp_procs_different_base_addr ){
|
2005-05-24 02:06:50 +04:00
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
/* set flag indicating btl has been inited */
|
|
|
|
btl_sm->btl_inited=true;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set connectivity */
|
|
|
|
cnt=0;
|
2006-10-20 23:28:12 +04:00
|
|
|
for(proc = 0 ; proc < (int32_t)nprocs ; proc++ ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
struct mca_btl_base_endpoint_t* peer = peers[proc];
|
2005-05-24 02:06:50 +04:00
|
|
|
if(peer == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tmp_ptr=(volatile char **)
|
2005-06-30 09:50:55 +04:00
|
|
|
( (char *)mca_btl_sm_component.sm_ctl_header->
|
2005-05-24 02:06:50 +04:00
|
|
|
segment_header.base_shared_mem_segment +
|
2005-06-30 09:50:55 +04:00
|
|
|
(long)mca_btl_sm_component.sm_mpool->mpool_base(mca_btl_sm_component.sm_mpool));
|
2005-05-24 02:06:50 +04:00
|
|
|
same_sm_base=(tmp_ptr[peer->peer_smp_rank] ==
|
2005-06-30 09:50:55 +04:00
|
|
|
tmp_ptr[mca_btl_sm_component.my_smp_rank]);
|
2005-05-24 02:06:50 +04:00
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
if( SM_CONNECTED == mca_btl_sm_component.sm_proc_connect[proc] ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
if( same_sm_base ){
|
|
|
|
|
|
|
|
/* don't count if same process */
|
2005-06-30 09:50:55 +04:00
|
|
|
if( (mca_btl_sm_component.num_smp_procs+cnt ) ==
|
|
|
|
mca_btl_sm_component.my_smp_rank) {
|
2005-05-24 02:06:50 +04:00
|
|
|
cnt++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* set up the list of local processes with the same base
|
|
|
|
* shared memory virtual address as this process */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.list_smp_procs_same_base_addr
|
|
|
|
[mca_btl_sm_component.num_smp_procs_same_base_addr]=
|
2005-05-24 02:06:50 +04:00
|
|
|
cnt;
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.num_smp_procs_same_base_addr++;
|
2005-05-24 02:06:50 +04:00
|
|
|
cnt++;
|
|
|
|
/* add this proc to shared memory accessability list */
|
|
|
|
return_code=ompi_bitmap_set_bit(reachability,proc);
|
|
|
|
if( OMPI_SUCCESS != return_code ){
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* set up the list of local processes with the same base
|
|
|
|
* shared memory virtual address as this process */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.list_smp_procs_different_base_addr
|
|
|
|
[mca_btl_sm_component.num_smp_procs_different_base_addr]=
|
2005-05-24 02:06:50 +04:00
|
|
|
cnt;
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.num_smp_procs_different_base_addr++;
|
2005-05-24 02:06:50 +04:00
|
|
|
cnt++;
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_proc_connect[proc]=
|
2005-05-24 02:06:50 +04:00
|
|
|
SM_CONNECTED_DIFFERENT_BASE_ADDR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-07 01:13:49 +04:00
|
|
|
/* make sure we have enough eager fragmnents for each process */
|
|
|
|
return_code = ompi_free_list_resize(&mca_btl_sm_component.sm_frags1,
|
|
|
|
(mca_btl_sm_component.num_smp_procs + n_local_procs) * 2);
|
|
|
|
if (OMPI_SUCCESS != return_code) {
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
2005-05-24 02:06:50 +04:00
|
|
|
/* update the local smp process count */
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.num_smp_procs+=n_local_procs;
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
return return_code;
|
|
|
|
}
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
/* Note:: this routine assumes that mca_btl_sm_add_procs_same_base_addr
|
2005-05-24 02:06:50 +04:00
|
|
|
* has already been called to set up data structures needed by this
|
|
|
|
* routine */
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_sm_add_procs(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
2005-05-24 02:06:50 +04:00
|
|
|
size_t nprocs,
|
|
|
|
struct ompi_proc_t **procs,
|
2005-06-30 09:50:55 +04:00
|
|
|
struct mca_btl_base_endpoint_t **peers,
|
2005-05-24 02:06:50 +04:00
|
|
|
ompi_bitmap_t* reachability)
|
|
|
|
{
|
|
|
|
int return_code = OMPI_SUCCESS, tmp_cnt;
|
|
|
|
uint32_t proc, n_local_procs;
|
|
|
|
|
|
|
|
/* initializion */
|
|
|
|
for(proc=0 ; proc < nprocs ; proc++ ) {
|
|
|
|
peers[proc]=NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* figure out total number of local procs in current set */
|
|
|
|
tmp_cnt=0;
|
|
|
|
for(proc = 0 ; proc < nprocs ; proc++ ) {
|
|
|
|
if( (SM_CONNECTED_DIFFERENT_BASE_ADDR ==
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_proc_connect[proc]) ||
|
2005-05-24 02:06:50 +04:00
|
|
|
(SM_CONNECTED ==
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.sm_proc_connect[proc]) ) {
|
2005-05-24 02:06:50 +04:00
|
|
|
tmp_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* set connectivity */
|
|
|
|
n_local_procs=0;
|
|
|
|
for(proc = 0 ; proc < nprocs ; proc++ ) {
|
2005-11-12 17:04:46 +03:00
|
|
|
/* Same base address base */
|
|
|
|
if (SM_CONNECTED == mca_btl_sm_component.sm_proc_connect[proc]) {
|
2005-05-24 02:06:50 +04:00
|
|
|
n_local_procs++;
|
|
|
|
}
|
|
|
|
|
2005-11-12 17:04:46 +03:00
|
|
|
/* Different base address case */
|
|
|
|
else if (SM_CONNECTED_DIFFERENT_BASE_ADDR ==
|
|
|
|
mca_btl_sm_component.sm_proc_connect[proc]) {
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
/* add this proc to shared memory accessability list */
|
|
|
|
return_code=ompi_bitmap_set_bit(reachability,proc);
|
|
|
|
if( OMPI_SUCCESS != return_code ){
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the peers information */
|
2006-08-24 20:38:08 +04:00
|
|
|
peers[proc] = (struct mca_btl_base_endpoint_t*)malloc(sizeof(struct mca_btl_base_endpoint_t));
|
2005-05-24 02:06:50 +04:00
|
|
|
if( NULL == peers[proc] ){
|
|
|
|
return_code=OMPI_ERR_OUT_OF_RESOURCE;
|
|
|
|
goto CLEANUP;
|
|
|
|
}
|
2005-06-30 09:50:55 +04:00
|
|
|
peers[proc]->my_smp_rank=mca_btl_sm_component.my_smp_rank;
|
|
|
|
/* subtract tmp_cnt, since mca_btl_sm_add_procs_same_base_addr
|
2005-05-24 02:06:50 +04:00
|
|
|
* already added these into num_smp_procs */
|
|
|
|
peers[proc]->peer_smp_rank=n_local_procs+
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_component.num_smp_procs-tmp_cnt;
|
2006-05-24 20:15:07 +04:00
|
|
|
#if OMPI_ENABLE_PROGRESS_THREADS
|
|
|
|
peers[proc]->fifo_fd =
|
|
|
|
mca_btl_sm_component.sm_peers[peers[proc]->peer_smp_rank]->fifo_fd;
|
|
|
|
#endif
|
2005-05-24 02:06:50 +04:00
|
|
|
n_local_procs++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CLEANUP:
|
|
|
|
/* free local memory */
|
2005-06-30 09:50:55 +04:00
|
|
|
if(mca_btl_sm_component.sm_proc_connect){
|
|
|
|
free(mca_btl_sm_component.sm_proc_connect);
|
|
|
|
mca_btl_sm_component.sm_proc_connect=NULL;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return return_code;
|
|
|
|
}
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_sm_del_procs(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
2005-05-24 02:06:50 +04:00
|
|
|
size_t nprocs,
|
|
|
|
struct ompi_proc_t **procs,
|
2005-06-30 09:50:55 +04:00
|
|
|
struct mca_btl_base_endpoint_t **peers)
|
2005-05-24 02:06:50 +04:00
|
|
|
{
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2005-06-30 09:50:55 +04:00
|
|
|
* MCA->BTL Clean up any resources held by BTL module
|
2005-05-24 02:06:50 +04:00
|
|
|
* before the module is unloaded.
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module.
|
2005-05-24 02:06:50 +04:00
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* Prior to unloading a BTL module, the MCA framework will call
|
|
|
|
* the BTL finalize method of the module. Any resources held by
|
|
|
|
* the BTL should be released and if required the memory corresponding
|
|
|
|
* to the BTL module freed.
|
2005-05-24 02:06:50 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_sm_finalize(struct mca_btl_base_module_t* btl)
|
2005-05-24 02:06:50 +04:00
|
|
|
{
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a callback function that is called on receipt
|
|
|
|
* of a fragment.
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
2005-05-24 02:06:50 +04:00
|
|
|
* @return Status indicating if cleanup was successful
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* When the process list changes, the PML notifies the BTL of the
|
2005-05-24 02:06:50 +04:00
|
|
|
* change, to provide the opportunity to cleanup or release any
|
|
|
|
* resources associated with the peer.
|
|
|
|
*/
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_sm_register(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
mca_btl_base_tag_t tag,
|
|
|
|
mca_btl_base_module_recv_cb_fn_t cbfunc,
|
2005-05-24 02:06:50 +04:00
|
|
|
void* cbdata)
|
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_t* sm_btl = (mca_btl_sm_t*)btl;
|
|
|
|
sm_btl->sm_reg[tag].cbfunc = cbfunc;
|
|
|
|
sm_btl->sm_reg[tag].cbdata = cbdata;
|
2005-05-24 02:06:50 +04:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-02-13 15:01:36 +03:00
|
|
|
/*
|
|
|
|
* Register callback function for error handling..
|
|
|
|
*/
|
|
|
|
int mca_btl_sm_register_error_cb(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
mca_btl_base_module_error_cb_fn_t cbfunc)
|
|
|
|
{
|
|
|
|
mca_btl_sm_t *sm_btl = (mca_btl_sm_t *)btl;
|
|
|
|
sm_btl->error_cb = cbfunc;
|
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
2005-05-24 02:06:50 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate a segment.
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
2005-05-24 02:06:50 +04:00
|
|
|
* @param size (IN) Request segment size.
|
|
|
|
*/
|
2005-06-30 09:50:55 +04:00
|
|
|
extern mca_btl_base_descriptor_t* mca_btl_sm_alloc(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
2005-05-24 02:06:50 +04:00
|
|
|
size_t size)
|
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_frag_t* frag;
|
2005-05-24 02:06:50 +04:00
|
|
|
int rc;
|
2005-06-30 09:50:55 +04:00
|
|
|
if(size <= mca_btl_sm_component.eager_limit) {
|
|
|
|
MCA_BTL_SM_FRAG_ALLOC1(frag,rc);
|
2005-09-07 17:40:22 +04:00
|
|
|
} else if (size <= mca_btl_sm_component.max_frag_size) {
|
2005-06-30 09:50:55 +04:00
|
|
|
MCA_BTL_SM_FRAG_ALLOC2(frag,rc);
|
2005-09-07 17:40:22 +04:00
|
|
|
} else {
|
|
|
|
return NULL;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
2006-10-07 01:13:49 +04:00
|
|
|
|
|
|
|
if (frag != NULL) {
|
|
|
|
frag->segment.seg_len = size;
|
|
|
|
}
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
return (mca_btl_base_descriptor_t*)frag;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
2006-10-07 01:13:49 +04:00
|
|
|
|
2005-05-24 02:06:50 +04:00
|
|
|
/**
|
2005-06-30 09:50:55 +04:00
|
|
|
* Return a segment allocated by this BTL.
|
2005-05-24 02:06:50 +04:00
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
2005-05-24 02:06:50 +04:00
|
|
|
* @param segment (IN) Allocated segment.
|
|
|
|
*/
|
2005-06-30 09:50:55 +04:00
|
|
|
extern int mca_btl_sm_free(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
mca_btl_base_descriptor_t* des)
|
2005-05-24 02:06:50 +04:00
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_frag_t* frag = (mca_btl_sm_frag_t*)des;
|
2006-05-31 18:24:32 +04:00
|
|
|
MCA_BTL_SM_FRAG_RETURN(frag);
|
|
|
|
|
2005-05-24 02:06:50 +04:00
|
|
|
return OMPI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pack data
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
2005-05-24 02:06:50 +04:00
|
|
|
*/
|
2005-06-30 09:50:55 +04:00
|
|
|
struct mca_btl_base_descriptor_t* mca_btl_sm_prepare_src(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
struct mca_btl_base_endpoint_t* endpoint,
|
2005-06-25 01:12:38 +04:00
|
|
|
mca_mpool_base_registration_t* registration,
|
2005-05-24 02:06:50 +04:00
|
|
|
struct ompi_convertor_t* convertor,
|
|
|
|
size_t reserve,
|
|
|
|
size_t* size)
|
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_frag_t* frag;
|
2005-06-01 18:34:22 +04:00
|
|
|
struct iovec iov;
|
|
|
|
uint32_t iov_count = 1;
|
2005-06-08 23:13:28 +04:00
|
|
|
size_t max_data = *size;
|
2005-06-01 18:34:22 +04:00
|
|
|
int rc;
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
MCA_BTL_SM_FRAG_ALLOC2(frag, rc);
|
2005-06-01 18:34:22 +04:00
|
|
|
if(NULL == frag) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-09 00:38:03 +04:00
|
|
|
if(reserve + max_data > frag->size) {
|
2005-06-02 01:09:43 +04:00
|
|
|
max_data = frag->size - reserve;
|
2005-06-01 18:34:22 +04:00
|
|
|
}
|
|
|
|
iov.iov_len = max_data;
|
2006-08-24 20:38:08 +04:00
|
|
|
iov.iov_base = (IOVBASE_TYPE*)(((unsigned char*)(frag+1)) + reserve);
|
2005-06-01 18:34:22 +04:00
|
|
|
|
2006-10-27 03:11:26 +04:00
|
|
|
rc = ompi_convertor_pack(convertor, &iov, &iov_count, &max_data );
|
2005-06-01 18:34:22 +04:00
|
|
|
if(rc < 0) {
|
2006-05-31 18:24:32 +04:00
|
|
|
MCA_BTL_SM_FRAG_RETURN(frag);
|
2005-06-01 18:34:22 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2005-06-09 00:38:03 +04:00
|
|
|
frag->segment.seg_len = reserve + max_data;
|
2005-06-01 18:34:22 +04:00
|
|
|
*size = max_data;
|
|
|
|
return &frag->base;
|
2005-05-24 02:06:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initiate a send to the peer.
|
|
|
|
*
|
2005-06-30 09:50:55 +04:00
|
|
|
* @param btl (IN) BTL module
|
|
|
|
* @param peer (IN) BTL peer addressing
|
2005-05-24 02:06:50 +04:00
|
|
|
*/
|
|
|
|
|
2005-06-30 09:50:55 +04:00
|
|
|
int mca_btl_sm_send(
|
|
|
|
struct mca_btl_base_module_t* btl,
|
|
|
|
struct mca_btl_base_endpoint_t* endpoint,
|
|
|
|
struct mca_btl_base_descriptor_t* descriptor,
|
|
|
|
mca_btl_base_tag_t tag)
|
2005-05-24 02:06:50 +04:00
|
|
|
{
|
2005-06-30 09:50:55 +04:00
|
|
|
mca_btl_sm_frag_t* frag = (mca_btl_sm_frag_t*)descriptor;
|
2005-05-24 02:06:50 +04:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
frag->tag = tag;
|
2005-06-30 09:50:55 +04:00
|
|
|
frag->type = MCA_BTL_SM_FRAG_SEND;
|
2005-05-24 02:06:50 +04:00
|
|
|
frag->rc = OMPI_SUCCESS;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* post the descriptor in the queue - post with the relative
|
|
|
|
* address
|
|
|
|
*/
|
2005-09-12 00:55:22 +04:00
|
|
|
MCA_BTL_SM_FIFO_WRITE(endpoint, endpoint->my_smp_rank, endpoint->peer_smp_rank, frag, rc);
|
2005-05-24 02:06:50 +04:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|