int mca_bcol_basesmuma_register_sm(void *context_data, void *base, size_t size, void **reg_desc) { /* local variables */ int ret = OMPI_SUCCESS; mca_bcol_basesmuma_component_t *cs = &mca_bcol_basesmuma_component; bcol_basesmuma_registration_data_t *sm_reg = (bcol_basesmuma_registration_data_t*) context_data; /* cache some info on sm_reg aka "context_data", you'll need it later */ sm_reg->base_addr = base; sm_reg->size = size; /* call into the shared memory registration function in smcm * we need to be sure that the memory is page aligned in order * to "map_fixed" */ sm_reg->sm_mmap = bcol_basesmuma_smcm_mem_reg(base, size, sm_reg->data_seg_alignment, sm_reg->file_name); if(NULL == sm_reg->sm_mmap) { opal_output (ompi_bcol_base_framework.framework_output, "Bcol_basesmuma memory registration error"); return OMPI_ERROR; } /* don't let other communicators re-register me! */ cs->mpool_inited = true; /* alias back to component */ cs->sm_payload_structs = sm_reg->sm_mmap; return ret; }
/* This routine is used to allocate shared memory for the the shared * memory control regions. */ int mca_bcol_basesmuma_allocate_sm_ctl_memory(mca_bcol_basesmuma_component_t *cs) { /* local variables */ int name_length, ret; size_t ctl_length; char *name, *ctl_mem; /* set the file name */ name_length=asprintf(&name, "%s"OPAL_PATH_SEP"%s""%0d", ompi_process_info.job_session_dir, cs->clt_base_fname, (int)getpid()); if( 0 > name_length ) { return OMPI_ERROR; } /* make sure name is not too long */ if ( OPAL_PATH_MAX < (name_length-1) ) { return OMPI_ERROR; } /* compute segment length */ ctl_length=(cs->basesmuma_num_mem_banks* cs->basesmuma_num_regions_per_bank+cs->basesmuma_num_mem_banks) *sizeof(mca_bcol_basesmuma_ctl_struct_t)*cs->n_groups_supported; /* need two banks of memory per group - for algorithms that have * user payload, and those that don't */ ctl_length*=2; /* add space for internal library management purposes */ ctl_length+=cs->my_scratch_shared_memory_size; /* round up to multiple of page size */ ctl_length=(ctl_length-1)/getpagesize()+1; ctl_length*=getpagesize(); /* allocate memory that will be mmaped */ ctl_mem=(char *)valloc(ctl_length); if( !ctl_mem) { return OMPI_ERR_OUT_OF_RESOURCE; } /* allocate the shared file */ cs->sm_ctl_structs=bcol_basesmuma_smcm_mem_reg(ctl_mem, ctl_length,getpagesize(),name); if( !cs->sm_ctl_structs) { fprintf(stderr," In mca_bcol_basesmuma_allocate_sm_ctl_memory failed to allocathe backing file %s \n",name); ret=OMPI_ERR_OUT_OF_RESOURCE; goto Error; } /* free the memory allocated by asprintf for the file name - * in mca_base_smcm_mem_reg this name is copied into a new * memory location */ free(name); /* successful return */ return OMPI_SUCCESS; Error: if(name) { free(name); } return ret; }