
The expected sequence of events for processing info during object creation is that if there's an incoming info arg, it is opal_info_dup()ed into the obj at obj->s_info first. Then interested components register callbacks for keys they want to know about using opal_infosubscribe_infosubscribe(). Inside info_subscribe_subscribe() the specified callback() is called with whatever matching k/v is in the object's info, or with the default. The return string from the callback goes into the new k/v stored in info, and the input k/v is saved as __IN_<key>/<val>. It's saved the same way whether the input came from info or whether it was a default. A null return from the callback indicates an ignored key/val, and no k/v is stored for it, but an __IN_<key>/<val> is still kept so we still have access to the original. At MPI_*_set_info() time, opal_infosubscribe_change_info() is used. That function calls the registered callbacks for each item in the provided info. If the callback returns non-null, the info is updated with that k/v, or if the callback returns null, that key is deleted from info. An __IN_<key>/<val> is saved either way, and overwrites any previously saved value. When MPI_*_get_info() is called, opal_info_dup_mpistandard() is used, which allows relatively easy changes in interpretation of the standard, by looking at both the <key>/<val> and __IN_<key>/<val> in info. Right now it does 1. includes system extras, eg k/v defaults not expliclty set by the user 2. omits ignored keys 3. shows input values, not callback modifications, eg not the internal values Currently the callbacks are doing things like return some_condition ? "true" : "false" that is, returning static strings that are not to be freed. If the return strings start becoming more dynamic in the future I don't see how unallocated strings could support that, so I'd propose a change for the future that the callback()s registered with info_subscribe_subscribe() do a strdup on their return, and we change the callers of callback() to free the strings it returns (there are only two callers). Rough outline of the smaller changes spread over the less central files: comm.c initialize comm->super.s_info to NULL copy into comm->super.s_info in comm creation calls that provide info OBJ_RELEASE comm->super.s_info at free time comm_init.c initialize comm->super.s_info to NULL file.c copy into file->super.s_info if file creation provides info OBJ_RELEASE file->super.s_info at free time win.c copy into win->super.s_info if win creation provides info OBJ_RELEASE win->super.s_info at free time comm_get_info.c file_get_info.c win_get_info.c change_info() if there's no info attached (shouldn't happen if callbacks are registered) copy the info for the user The other category of change is generally addressing compiler warnings where ompi_info_t and opal_info_t were being used a little too interchangably. An ompi_info_t* contains an opal_info_t*, at &(ompi_info->super) Also this commit updates the copyrights. Signed-off-by: Mark Allen <markalle@us.ibm.com>
200 строки
7.0 KiB
C
200 строки
7.0 KiB
C
/*
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
* University Research and Technology
|
|
* Corporation. All rights reserved.
|
|
* Copyright (c) 2004-2017 The University of Tennessee and The University
|
|
* of Tennessee Research Foundation. All rights
|
|
* reserved.
|
|
* 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 (c) 2013-2017 University of Houston. All rights reserved.
|
|
* Copyright (c) 2015 Research Organization for Information Science
|
|
* and Technology (RIST). All rights reserved.
|
|
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
|
|
* $COPYRIGHT$
|
|
*
|
|
* Additional copyrights may follow
|
|
*
|
|
* $HEADER$
|
|
*/
|
|
|
|
|
|
#include "ompi_config.h"
|
|
#include "sharedfp_lockedfile.h"
|
|
|
|
#include "mpi.h"
|
|
#include "ompi/constants.h"
|
|
#include "ompi/group/group.h"
|
|
#include "ompi/proc/proc.h"
|
|
#include "ompi/mca/sharedfp/sharedfp.h"
|
|
#include "ompi/mca/sharedfp/base/base.h"
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
#include <sys/stat.h>
|
|
#endif
|
|
#include <fcntl.h>
|
|
|
|
int mca_sharedfp_lockedfile_file_open (struct ompi_communicator_t *comm,
|
|
const char* filename,
|
|
int amode,
|
|
struct opal_info_t *info,
|
|
mca_io_ompio_file_t *fh)
|
|
{
|
|
int err = MPI_SUCCESS;
|
|
char * lockedfilename;
|
|
int handle, rank;
|
|
struct mca_sharedfp_lockedfile_data * module_data = NULL;
|
|
struct mca_sharedfp_base_data_t* sh;
|
|
mca_io_ompio_file_t * shfileHandle, *ompio_fh;
|
|
mca_io_ompio_data_t *data;
|
|
|
|
/*------------------------------------------------------------*/
|
|
/*Open the same file again without shared file pointer support*/
|
|
/*------------------------------------------------------------*/
|
|
shfileHandle = (mca_io_ompio_file_t *)malloc(sizeof(mca_io_ompio_file_t));
|
|
err = mca_common_ompio_file_open(comm,filename,amode,info,shfileHandle,false);
|
|
if ( OMPI_SUCCESS != err) {
|
|
opal_output(0, "mca_sharedfp_lockedfile_file_open: Error during file open\n");
|
|
return err;
|
|
}
|
|
shfileHandle->f_fh = fh->f_fh;
|
|
data = (mca_io_ompio_data_t *) fh->f_fh->f_io_selected_data;
|
|
ompio_fh = &data->ompio_fh;
|
|
|
|
err = mca_common_ompio_set_view (shfileHandle,
|
|
ompio_fh->f_disp,
|
|
ompio_fh->f_etype,
|
|
ompio_fh->f_orig_filetype,
|
|
ompio_fh->f_datarep,
|
|
&(MPI_INFO_NULL->super));
|
|
|
|
|
|
/*Memory is allocated here for the sh structure*/
|
|
sh = (struct mca_sharedfp_base_data_t*)malloc(sizeof(struct mca_sharedfp_base_data_t));
|
|
if ( NULL == sh){
|
|
opal_output(0, "mca_sharedfp_lockedfile_file_open: Error, unable to malloc f_sharedfp_ptr struct\n");
|
|
free ( shfileHandle);
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
}
|
|
/*Populate the sh file structure based on the implementation*/
|
|
sh->sharedfh = shfileHandle; /* Shared file pointer*/
|
|
sh->global_offset = 0; /* Global Offset*/
|
|
sh->comm = comm; /* Communicator*/
|
|
sh->selected_module_data = NULL;
|
|
|
|
rank = ompi_comm_rank ( sh->comm);
|
|
|
|
/*Open a new file which will maintain the pointer for this file open*/
|
|
if ( mca_sharedfp_lockedfile_verbose ) {
|
|
opal_output(ompi_sharedfp_base_framework.framework_output,
|
|
"mca_sharedfp_lockedfile_file_open: open locked file.\n");
|
|
}
|
|
|
|
|
|
module_data = (struct mca_sharedfp_lockedfile_data*)malloc(sizeof(struct mca_sharedfp_lockedfile_data));
|
|
if ( NULL == module_data ) {
|
|
opal_output(ompi_sharedfp_base_framework.framework_output,
|
|
"mca_sharedfp_lockedfile_file_open: Error, unable to malloc lockedfile_data struct\n");
|
|
free (shfileHandle);
|
|
free (sh);
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
}
|
|
|
|
opal_jobid_t masterjobid;
|
|
if ( 0 == comm->c_my_rank ) {
|
|
ompi_proc_t *masterproc = ompi_group_peer_lookup(comm->c_local_group, 0 );
|
|
masterjobid = OMPI_CAST_RTE_NAME(&masterproc->super.proc_name)->jobid;
|
|
}
|
|
comm->c_coll->coll_bcast ( &masterjobid, 1, MPI_UNSIGNED, 0, comm,
|
|
comm->c_coll->coll_bcast_module );
|
|
|
|
size_t filenamelen = strlen(filename) + 16;
|
|
lockedfilename = (char*)malloc(sizeof(char) * filenamelen);
|
|
if ( NULL == lockedfilename ) {
|
|
free (shfileHandle);
|
|
free (sh);
|
|
free (module_data);
|
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
|
}
|
|
snprintf(lockedfilename, filenamelen, "%s-%u%s",filename,masterjobid,".lock");
|
|
module_data->filename = lockedfilename;
|
|
|
|
/*-------------------------------------------------*/
|
|
/*Open the lockedfile without shared file pointer */
|
|
/*-------------------------------------------------*/
|
|
if ( 0 == rank ) {
|
|
OMPI_MPI_OFFSET_TYPE position=0;
|
|
/*only let main process initialize file pointer,
|
|
*therefore there is no need to lock the file
|
|
*/
|
|
handle = open ( lockedfilename, O_RDWR | O_CREAT, 0644 );
|
|
write ( handle, &position, sizeof(OMPI_MPI_OFFSET_TYPE) );
|
|
close ( handle );
|
|
}
|
|
comm->c_coll->coll_barrier ( comm, comm->c_coll->coll_barrier_module );
|
|
|
|
handle = open ( lockedfilename, O_RDWR, 0644 );
|
|
if ( -1 == handle ) {
|
|
opal_output(0, "[%d]mca_sharedfp_lockedfile_file_open: Error during file open\n", rank);
|
|
free (shfileHandle);
|
|
free (sh);
|
|
free(module_data);
|
|
return OMPI_ERROR;
|
|
}
|
|
|
|
/*Store the new file handle*/
|
|
module_data->handle = handle;
|
|
/* Assign the lockedfile_data to sh->handle*/
|
|
sh->selected_module_data = module_data;
|
|
/*remember the shared file handle*/
|
|
fh->f_sharedfp_data = sh;
|
|
|
|
comm->c_coll->coll_barrier ( comm, comm->c_coll->coll_barrier_module );
|
|
|
|
return err;
|
|
}
|
|
|
|
int mca_sharedfp_lockedfile_file_close (mca_io_ompio_file_t *fh)
|
|
{
|
|
int err = OMPI_SUCCESS;
|
|
struct mca_sharedfp_lockedfile_data * module_data = NULL;
|
|
struct mca_sharedfp_base_data_t *sh;
|
|
int rank = ompi_comm_rank ( fh->f_comm );
|
|
|
|
if ( fh->f_sharedfp_data==NULL){
|
|
/* Can happen with lazy_open being set */
|
|
if ( mca_sharedfp_lockedfile_verbose ) {
|
|
opal_output(0, "sharedfp_lockedfile_file_close - shared file pointer structure not initialized\n");
|
|
}
|
|
return OMPI_SUCCESS;
|
|
}
|
|
sh = fh->f_sharedfp_data;
|
|
|
|
module_data = (lockedfile_data*)(sh->selected_module_data);
|
|
if ( module_data) {
|
|
/*Close lockedfile handle*/
|
|
if ( module_data->handle) {
|
|
close (module_data->handle );
|
|
if ( 0 == rank ) {
|
|
unlink ( module_data->filename);
|
|
}
|
|
}
|
|
if ( NULL != module_data->filename ){
|
|
free ( module_data->filename);
|
|
}
|
|
free ( module_data );
|
|
}
|
|
|
|
/* Close the main file opened by this component*/
|
|
err = mca_common_ompio_file_close(sh->sharedfh);
|
|
|
|
/*free shared file pointer data struct*/
|
|
free(sh);
|
|
|
|
return err;
|
|
|
|
}
|
|
|