Skip to content

Commit 5e166c8

Browse files
committed
Merge pull request #745 from edgargabriel/pr/sharedfp-sm-logic3
Pr/sharedfp sm logic3
2 parents 579e43f + 8932387 commit 5e166c8

11 files changed

+240
-218
lines changed

ompi/mca/sharedfp/sm/configure.m4

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- shell-script -*-
2+
#
3+
# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
4+
# University Research and Technology
5+
# Corporation. All rights reserved.
6+
# Copyright (c) 2004-2005 The University of Tennessee and The University
7+
# of Tennessee Research Foundation. All rights
8+
# reserved.
9+
# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
10+
# University of Stuttgart. All rights reserved.
11+
# Copyright (c) 2004-2012 The Regents of the University of California.
12+
# All rights reserved.
13+
# Copyright (c) 2010-2014 Cisco Systems, Inc. All rights reserved.
14+
# Copyright (c) 2008-2015 University of Houston. All rights reserved.
15+
# $COPYRIGHT$
16+
#
17+
# Additional copyrights may follow
18+
#
19+
# $HEADER$
20+
#
21+
22+
# MCA_sharedfp_sm_CONFIG(action-if-can-compile,
23+
# [action-if-cant-compile])
24+
# ------------------------------------------------
25+
AC_DEFUN([MCA_ompi_sharedfp_sm_CONFIG],[
26+
AC_CONFIG_FILES([ompi/mca/sharedfp/sm/Makefile])
27+
28+
sharedfp_sm_happy=no
29+
AC_CHECK_HEADER([semaphore.h],
30+
[AC_CHECK_FUNCS([sem_open],[sharedfp_sm_happy=yes],[])])
31+
32+
AC_CHECK_HEADER([semaphore.h],
33+
[AC_CHECK_FUNCS([sem_init],[sharedfp_sm_happy=yes],[])])
34+
35+
AS_IF([test "$sharedfp_sm_happy" = "yes"],
36+
[$1],
37+
[$2])
38+
])dnl

ompi/mca/sharedfp/sm/sharedfp_sm.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ struct mca_sharedfp_base_module_1_0_0_t * mca_sharedfp_sm_component_file_query(m
8383
ompi_group_t *group = comm->c_local_group;
8484

8585
for (i = 0; i < size; ++i) {
86-
proc = ompi_group_peer_lookup(group,i);
87-
if (!OPAL_PROC_ON_LOCAL_NODE(proc->super.proc_flags)){
88-
opal_output(ompi_sharedfp_base_framework.framework_output,
89-
"mca_sharedfp_sm_component_file_query: Disqualifying myself: (%d/%s) "
90-
"not all processes are on the same node.",
91-
comm->c_contextid, comm->c_name);
92-
return NULL;
93-
}
86+
proc = ompi_group_peer_lookup(group,i);
87+
if (!OPAL_PROC_ON_LOCAL_NODE(proc->super.proc_flags)){
88+
opal_output(ompi_sharedfp_base_framework.framework_output,
89+
"mca_sharedfp_sm_component_file_query: Disqualifying myself: (%d/%s) "
90+
"not all processes are on the same node.",
91+
comm->c_contextid, comm->c_name);
92+
return NULL;
93+
}
9494
}
9595
/* This module can run */
9696
*priority = mca_sharedfp_sm_priority;

ompi/mca/sharedfp/sm/sharedfp_sm.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
1212
* Copyright (c) 2008-2015 University of Houston. All rights reserved.
13+
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
1314
* $COPYRIGHT$
1415
*
1516
* Additional copyrights may follow
@@ -100,9 +101,8 @@ int mca_sharedfp_sm_iwrite (mca_io_ompio_file_t *fh,
100101
/*--------------------------------------------------------------*
101102
*Structures and definitions only for this component
102103
*--------------------------------------------------------------*/
103-
104-
struct sm_offset{
105-
sem_t *mutex; /* the mutex: a Posix memory-based unnamed semaphore */
104+
struct mca_sharedfp_sm_offset{
105+
sem_t mutex; /* the mutex: a POSIX memory-based unnamed semaphore */
106106
long long offset; /* and the shared file pointer offset */
107107
};
108108

@@ -111,10 +111,13 @@ struct sm_offset{
111111
*/
112112
struct mca_sharedfp_sm_data
113113
{
114-
struct sm_offset * sm_offset_ptr;
114+
struct mca_sharedfp_sm_offset * sm_offset_ptr;
115115
/*save filename so that we can remove the file on close*/
116116
char * sm_filename;
117-
sem_t *mutex; /* the mutex: a Posix memory-based named semaphore */
117+
/* The mutex: it will either point to a POSIX memory-based named
118+
semaphore, or it will point to the a POSIX memory-based unnamed
119+
semaphore located in sm_offset_ptr->mutex. */
120+
sem_t *mutex;
118121
char *sem_name; /* Name of the semaphore */
119122
};
120123

ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Copyright (c) 2013 Intel, Inc. All rights reserved.
1414
* Copyright (c) 2015 Research Organization for Information Science
1515
* and Technology (RIST). All rights reserved.
16+
* Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
1617
* $COPYRIGHT$
1718
*
1819
* Additional copyrights may follow
@@ -54,8 +55,8 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
5455
mca_io_ompio_file_t * shfileHandle;
5556
char * filename_basename;
5657
char * sm_filename;
57-
struct sm_offset * sm_offset_ptr;
58-
struct sm_offset sm_offset;
58+
struct mca_sharedfp_sm_offset * sm_offset_ptr;
59+
struct mca_sharedfp_sm_offset sm_offset;
5960
int sm_fd;
6061
int rank;
6162

@@ -71,27 +72,27 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
7172

7273
/*Memory is allocated here for the sh structure*/
7374
if ( mca_sharedfp_sm_verbose ) {
74-
printf( "mca_sharedfp_sm_file_open: malloc f_sharedfp_ptr struct\n");
75+
printf( "mca_sharedfp_sm_file_open: malloc f_sharedfp_ptr struct\n");
7576
}
7677

7778
sh = (struct mca_sharedfp_base_data_t*)malloc(sizeof(struct mca_sharedfp_base_data_t));
7879
if ( NULL == sh ) {
79-
opal_output(0, "mca_sharedfp_sm_file_open: Error, unable to malloc f_sharedfp_ptr struct\n");
80-
free(shfileHandle);
81-
return OMPI_ERR_OUT_OF_RESOURCE;
80+
opal_output(0, "mca_sharedfp_sm_file_open: Error, unable to malloc f_sharedfp_ptr struct\n");
81+
free(shfileHandle);
82+
return OMPI_ERR_OUT_OF_RESOURCE;
8283
}
8384

8485
/*Populate the sh file structure based on the implementation*/
85-
sh->sharedfh = shfileHandle; /* Shared file pointer*/
86-
sh->global_offset = 0; /* Global Offset*/
87-
sh->comm = comm; /* Communicator*/
86+
sh->sharedfh = shfileHandle; /* Shared file pointer*/
87+
sh->global_offset = 0; /* Global Offset*/
88+
sh->comm = comm; /* Communicator*/
8889
sh->selected_module_data = NULL;
8990

9091
rank = ompi_comm_rank ( sh->comm );
9192

9293
/*Open a shared memory segment which will hold the shared file pointer*/
9394
if ( mca_sharedfp_sm_verbose ) {
94-
printf( "mca_sharedfp_sm_file_open: allocatge shared memory segment.\n");
95+
printf( "mca_sharedfp_sm_file_open: allocatge shared memory segment.\n");
9596
}
9697

9798

@@ -135,26 +136,25 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
135136
return OMPI_ERROR;
136137
}
137138

138-
free(sm_filename);
139139
sm_data->sm_filename = sm_filename;
140140

141141
/*TODO: is it necessary to write to the file first?*/
142142
if( 0 == rank ){
143-
memset ( &sm_offset, 0, sizeof (struct sm_offset ));
144-
write ( sm_fd, &sm_offset, sizeof(struct sm_offset));
143+
memset ( &sm_offset, 0, sizeof (struct mca_sharedfp_sm_offset ));
144+
write ( sm_fd, &sm_offset, sizeof(struct mca_sharedfp_sm_offset));
145145
}
146146
comm->c_coll.coll_barrier (comm, comm->c_coll.coll_barrier_module );
147147

148148
/*the file has been written to, now we can map*/
149-
sm_offset_ptr = mmap(NULL, sizeof(struct sm_offset), PROT_READ | PROT_WRITE,
150-
MAP_SHARED, sm_fd, 0);
149+
sm_offset_ptr = mmap(NULL, sizeof(struct mca_sharedfp_sm_offset), PROT_READ | PROT_WRITE,
150+
MAP_SHARED, sm_fd, 0);
151151

152152
close(sm_fd);
153153

154154
if ( sm_offset_ptr==MAP_FAILED){
155-
err = OMPI_ERROR;
156-
printf("mca_sharedfp_sm_file_open: Error, unable to mmap file: %s\n",sm_filename);
157-
printf("%s\n", strerror(errno));
155+
err = OMPI_ERROR;
156+
printf("mca_sharedfp_sm_file_open: Error, unable to mmap file: %s\n",sm_filename);
157+
printf("%s\n", strerror(errno));
158158
free(sm_filename);
159159
free(sm_data);
160160
free(sh);
@@ -165,43 +165,38 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
165165
/* Initialize semaphore so that is shared between processes. */
166166
/* the semaphore is shared by keeping it in the shared memory segment */
167167

168-
#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES
169-
if(sem_init(&sm_offset_ptr->mutex, 1, 1) != -1){
170-
#else
168+
#if defined(HAVE_SEM_OPEN)
171169
sm_data->sem_name = (char*) malloc( sizeof(char) * (strlen(filename_basename)+32) );
172170
sprintf(sm_data->sem_name,"OMPIO_sharedfp_sem_%s",filename_basename);
173171

174172
if( (sm_data->mutex = sem_open(sm_data->sem_name, O_CREAT, 0644, 1)) != SEM_FAILED ) {
173+
#elif defined(HAVE_SEM_INIT)
174+
sm_data->mutex = &sm_offset_ptr->mutex;
175+
if(sem_init(&sm_offset_ptr->mutex, 1, 1) != -1){
175176
#endif
176-
/*If opening was successful*/
177-
/*Store the new file handle*/
178-
sm_data->sm_offset_ptr = sm_offset_ptr;
179-
/* Assign the sm_data to sh->selected_module_data*/
180-
sh->selected_module_data = sm_data;
181-
/*remember the shared file handle*/
182-
fh->f_sharedfp_data = sh;
183-
184-
/*write initial zero*/
185-
if(rank==0){
186-
MPI_Offset position=0;
187-
188-
#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES
189-
sem_wait(sm_offset_ptr->mutex);
190-
sm_offset_ptr->offset=position;
191-
sem_post(sm_offset_ptr->mutex);
192-
#else
193-
sem_wait(sm_data->mutex);
194-
sm_offset_ptr->offset=position;
195-
sem_post(sm_data->mutex);
196-
#endif
197-
}
177+
/*If opening was successful*/
178+
/*Store the new file handle*/
179+
sm_data->sm_offset_ptr = sm_offset_ptr;
180+
/* Assign the sm_data to sh->selected_module_data*/
181+
sh->selected_module_data = sm_data;
182+
/*remember the shared file handle*/
183+
fh->f_sharedfp_data = sh;
184+
185+
/*write initial zero*/
186+
if(rank==0){
187+
MPI_Offset position=0;
188+
189+
sem_wait(sm_data->mutex);
190+
sm_offset_ptr->offset=position;
191+
sem_post(sm_data->mutex);
192+
}
198193
}else{
199194
free(sm_filename);
200-
free(sm_data);
201-
free(sh);
202-
free(shfileHandle);
203-
munmap(sm_offset_ptr, sizeof(struct sm_offset));
204-
err = OMPI_ERROR;
195+
free(sm_data);
196+
free(sh);
197+
free(shfileHandle);
198+
munmap(sm_offset_ptr, sizeof(struct mca_sharedfp_sm_offset));
199+
err = OMPI_ERROR;
205200
}
206201

207202
comm->c_coll.coll_barrier (comm, comm->c_coll.coll_barrier_module );
@@ -218,9 +213,9 @@ int mca_sharedfp_sm_file_close (mca_io_ompio_file_t *fh)
218213
struct mca_sharedfp_sm_data * file_data=NULL;
219214

220215
if( NULL == fh->f_sharedfp_data ){
221-
if ( mca_sharedfp_sm_verbose ) {
222-
printf("sharedfp_sm_file_close: shared file pointer structure not initialized\n");
223-
}
216+
if ( mca_sharedfp_sm_verbose ) {
217+
printf("sharedfp_sm_file_close: shared file pointer structure not initialized\n");
218+
}
224219
return OMPI_SUCCESS;
225220
}
226221
sh = fh->f_sharedfp_data;
@@ -236,14 +231,14 @@ int mca_sharedfp_sm_file_close (mca_io_ompio_file_t *fh)
236231
/*Close sm handle*/
237232
if (file_data->sm_offset_ptr) {
238233
/* destroy semaphore */
239-
#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES
240-
sem_destroy(file_data->sm_offset_ptr->mutex);
241-
#else
242-
sem_unlink (file_data->sem_name);
243-
free (file_data->sem_name);
234+
#if defined(HAVE_SEM_OPEN)
235+
sem_unlink (file_data->sem_name);
236+
free (file_data->sem_name);
237+
#elif defined(HAVE_SEM_INIT)
238+
sem_destroy(&file_data->sm_offset_ptr->mutex);
244239
#endif
245240
/*Release the shared memory segment.*/
246-
munmap(file_data->sm_offset_ptr,sizeof(struct sm_offset));
241+
munmap(file_data->sm_offset_ptr,sizeof(struct mca_sharedfp_sm_offset));
247242
/*Q: Do we need to delete the file? */
248243
remove(file_data->sm_filename);
249244
}

ompi/mca/sharedfp/sm/sharedfp_sm_get_position.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mca_sharedfp_sm_get_position(mca_io_ompio_file_t *fh,
3737

3838
if(fh->f_sharedfp_data==NULL){
3939
opal_output(ompi_sharedfp_base_framework.framework_output,
40-
"sharedfp_sm_write - opening the shared file pointer\n");
40+
"sharedfp_sm_write - opening the shared file pointer\n");
4141
shared_fp_base_module = fh->f_sharedfp;
4242

4343
ret = shared_fp_base_module->sharedfp_file_open(fh->f_comm,

ompi/mca/sharedfp/sm/sharedfp_sm_iread.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
#include "ompi/mca/sharedfp/sharedfp.h"
2727

2828
int mca_sharedfp_sm_iread(mca_io_ompio_file_t *fh,
29-
void *buf,
30-
int count,
31-
ompi_datatype_t *datatype,
32-
MPI_Request * request)
29+
void *buf,
30+
int count,
31+
ompi_datatype_t *datatype,
32+
MPI_Request * request)
3333
{
3434
int ret = OMPI_SUCCESS;
3535
OMPI_MPI_OFFSET_TYPE offset = 0;
@@ -39,9 +39,9 @@ int mca_sharedfp_sm_iread(mca_io_ompio_file_t *fh,
3939
mca_sharedfp_base_module_t * shared_fp_base_module = NULL;
4040

4141
if( NULL == fh->f_sharedfp_data){
42-
if ( mca_sharedfp_sm_verbose ) {
43-
printf("sharedfp_sm_iread: opening the shared file pointer\n");
44-
}
42+
if ( mca_sharedfp_sm_verbose ) {
43+
printf("sharedfp_sm_iread: opening the shared file pointer\n");
44+
}
4545
shared_fp_base_module = fh->f_sharedfp;
4646

4747
ret = shared_fp_base_module->sharedfp_file_open(fh->f_comm,
@@ -63,15 +63,15 @@ int mca_sharedfp_sm_iread(mca_io_ompio_file_t *fh,
6363
sh = fh->f_sharedfp_data;
6464

6565
if ( mca_sharedfp_sm_verbose ) {
66-
printf("sharedfp_sm_iread: Bytes Requested is %ld\n",bytesRequested);
66+
printf("sharedfp_sm_iread: Bytes Requested is %ld\n",bytesRequested);
6767
}
6868
/*Request the offset to write bytesRequested bytes*/
6969
ret = mca_sharedfp_sm_request_position(sh,bytesRequested,&offset);
7070

7171
if ( -1 != ret ) {
72-
if ( mca_sharedfp_sm_verbose ) {
73-
printf("sharedfp_sm_iread: Offset received is %lld\n",offset);
74-
}
72+
if ( mca_sharedfp_sm_verbose ) {
73+
printf("sharedfp_sm_iread: Offset received is %lld\n",offset);
74+
}
7575
/* Read the file */
7676
ret = ompio_io_ompio_file_iread_at(sh->sharedfh,offset,buf,count,datatype,request);
7777
}
@@ -90,8 +90,8 @@ int mca_sharedfp_sm_read_ordered_begin(mca_io_ompio_file_t *fh,
9090

9191

9292
int mca_sharedfp_sm_read_ordered_end(mca_io_ompio_file_t *fh,
93-
void *buf,
94-
ompi_status_public_t *status)
93+
void *buf,
94+
ompi_status_public_t *status)
9595
{
9696
opal_output(0,"mca_sharedfp_sm_read_ordered_end: NOT IMPLEMENTED\n");
9797
return OMPI_ERROR;

0 commit comments

Comments
 (0)