diff --git a/ompi/mca/sharedfp/sm/sharedfp_sm.h b/ompi/mca/sharedfp/sm/sharedfp_sm.h index 8f0ae91fc7..621324eb5f 100644 --- a/ompi/mca/sharedfp/sm/sharedfp_sm.h +++ b/ompi/mca/sharedfp/sm/sharedfp_sm.h @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2008 University of Houston. All rights reserved. + * Copyright (c) 2008-2015 University of Houston. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -102,8 +102,8 @@ int mca_sharedfp_sm_iwrite (mca_io_ompio_file_t *fh, *--------------------------------------------------------------*/ struct sm_offset{ - sem_t mutex; /* the mutex: a Posix memory-based semaphore */ - long long offset; /* and the shared file pointer offset */ + sem_t *mutex; /* the mutex: a Posix memory-based unnamed semaphore */ + long long offset; /* and the shared file pointer offset */ }; /*This structure will hang off of the mca_sharedfp_base_data_t's @@ -114,6 +114,8 @@ struct mca_sharedfp_sm_data struct sm_offset * sm_offset_ptr; /*save filename so that we can remove the file on close*/ char * sm_filename; + sem_t *mutex; /* the mutex: a Posix memory-based named semaphore */ + char *sem_name; /* Name of the semaphore */ }; typedef struct mca_sharedfp_sm_data sm_data; diff --git a/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c b/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c index 443f10ee7d..0cc1255280 100644 --- a/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c +++ b/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2013 University of Houston. All rights reserved. + * Copyright (c) 2013-2015 University of Houston. All rights reserved. * Copyright (c) 2013 Intel, Inc. All rights reserved. * $COPYRIGHT$ * @@ -156,7 +156,15 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm, /* Initialize semaphore so that is shared between processes. */ /* the semaphore is shared by keeping it in the shared memory segment */ + +#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES if(sem_init(&sm_offset_ptr->mutex, 1, 1) != -1){ +#else + sm_data->sem_name = (char*) malloc( sizeof(char) * (strlen(filename_basename)+32) ); + sprintf(sm_data->sem_name,"OMPIO_sharedfp_sem_%s",filename_basename); + + if( (sm_data->mutex = sem_open(sm_data->sem_name, O_CREAT, 0644, 1)) != SEM_FAILED ) { +#endif /*If opening was successful*/ /*Store the new file handle*/ sm_data->sm_offset_ptr = sm_offset_ptr; @@ -168,9 +176,16 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm, /*write initial zero*/ if(rank==0){ MPI_Offset position=0; - sem_wait(&sm_offset_ptr->mutex); + +#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES + sem_wait(sm_offset_ptr->mutex); sm_offset_ptr->offset=position; - sem_post(&sm_offset_ptr->mutex); + sem_post(sm_offset_ptr->mutex); +#else + sem_wait(sm_data->mutex); + sm_offset_ptr->offset=position; + sem_post(sm_data->mutex); +#endif } }else{ free(sm_data); @@ -211,7 +226,12 @@ int mca_sharedfp_sm_file_close (mca_io_ompio_file_t *fh) /*Close sm handle*/ if (file_data->sm_offset_ptr) { /* destroy semaphore */ - sem_destroy(&file_data->sm_offset_ptr->mutex); +#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES + sem_destroy(file_data->sm_offset_ptr->mutex); +#else + sem_unlink (file_data->sem_name); + free (file_data->sem_name); +#endif /*Release the shared memory segment.*/ munmap(file_data->sm_offset_ptr,sizeof(struct sm_offset)); /*Q: Do we need to delete the file? */ diff --git a/ompi/mca/sharedfp/sm/sharedfp_sm_request_position.c b/ompi/mca/sharedfp/sm/sharedfp_sm_request_position.c index dce6595e1b..6414c79209 100644 --- a/ompi/mca/sharedfp/sm/sharedfp_sm_request_position.c +++ b/ompi/mca/sharedfp/sm/sharedfp_sm_request_position.c @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2013 University of Houston. All rights reserved. + * Copyright (c) 2013-2015 University of Houston. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -47,7 +47,12 @@ int mca_sharedfp_sm_request_position(struct mca_sharedfp_base_data_t * sh, sm_offset_ptr = sm_data->sm_offset_ptr; /* Aquire an exclusive lock */ - sem_wait(&sm_offset_ptr->mutex); + +#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES + sem_wait(sm_offset_ptr->mutex); +#else + sem_wait(sm_data->mutex); +#endif if ( mca_sharedfp_sm_verbose ) { printf("Succeeded! Acquired sm lock.for rank=%d\n",rank); @@ -68,7 +73,12 @@ int mca_sharedfp_sm_request_position(struct mca_sharedfp_base_data_t * sh, if ( mca_sharedfp_sm_verbose ) { printf("Releasing sm lock...rank=%d",rank); } - sem_post(&sm_offset_ptr->mutex); + +#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES + sem_post(sm_offset_ptr->mutex); +#else + sem_post(sm_data->mutex); +#endif if ( mca_sharedfp_sm_verbose ) { printf("Released lock! released lock.for rank=%d\n",rank); } diff --git a/ompi/mca/sharedfp/sm/sharedfp_sm_seek.c b/ompi/mca/sharedfp/sm/sharedfp_sm_seek.c index 342dcf0069..a3d475101a 100644 --- a/ompi/mca/sharedfp/sm/sharedfp_sm_seek.c +++ b/ompi/mca/sharedfp/sm/sharedfp_sm_seek.c @@ -9,7 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. - * Copyright (c) 2013 University of Houston. All rights reserved. + * Copyright (c) 2013-2015 University of Houston. All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -120,7 +120,12 @@ mca_sharedfp_sm_seek (mca_io_ompio_file_t *fh, /* Aquire an exclusive lock */ sm_offset_ptr = sm_data->sm_offset_ptr; - sem_wait(&sm_offset_ptr->mutex); + +#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES + sem_wait(sm_offset_ptr->mutex); +#else + sem_wait(sm_data->mutex); +#endif if ( mca_sharedfp_sm_verbose ) { printf("sharedfp_sm_seek: Success! Acquired sm lock.for rank=%d\n",rank); @@ -129,7 +134,11 @@ mca_sharedfp_sm_seek (mca_io_ompio_file_t *fh, if ( mca_sharedfp_sm_verbose ) { printf("sharedfp_sm_seek: Releasing sm lock...rank=%d",rank); fflush(stdout); } - sem_post(&sm_offset_ptr->mutex); +#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES + sem_post(sm_offset_ptr->mutex); +#else + sem_post(sm_data->mutex); +#endif } /* since we are only letting process 0, update the current pointer