13
13
* Copyright (c) 2013 Intel, Inc. All rights reserved.
14
14
* Copyright (c) 2015 Research Organization for Information Science
15
15
* and Technology (RIST). All rights reserved.
16
+ * Copyright (c) 2015 Cisco Systems, Inc. All rights reserved.
16
17
* $COPYRIGHT$
17
18
*
18
19
* Additional copyrights may follow
@@ -54,8 +55,8 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
54
55
mca_io_ompio_file_t * shfileHandle ;
55
56
char * filename_basename ;
56
57
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 ;
59
60
int sm_fd ;
60
61
int rank ;
61
62
@@ -71,27 +72,27 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
71
72
72
73
/*Memory is allocated here for the sh structure*/
73
74
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" );
75
76
}
76
77
77
78
sh = (struct mca_sharedfp_base_data_t * )malloc (sizeof (struct mca_sharedfp_base_data_t ));
78
79
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 ;
82
83
}
83
84
84
85
/*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*/
88
89
sh -> selected_module_data = NULL ;
89
90
90
91
rank = ompi_comm_rank ( sh -> comm );
91
92
92
93
/*Open a shared memory segment which will hold the shared file pointer*/
93
94
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" );
95
96
}
96
97
97
98
@@ -135,26 +136,25 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
135
136
return OMPI_ERROR ;
136
137
}
137
138
138
- free (sm_filename );
139
139
sm_data -> sm_filename = sm_filename ;
140
140
141
141
/*TODO: is it necessary to write to the file first?*/
142
142
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 ));
145
145
}
146
146
comm -> c_coll .coll_barrier (comm , comm -> c_coll .coll_barrier_module );
147
147
148
148
/*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 );
151
151
152
152
close (sm_fd );
153
153
154
154
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 ));
158
158
free (sm_filename );
159
159
free (sm_data );
160
160
free (sh );
@@ -165,43 +165,38 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
165
165
/* Initialize semaphore so that is shared between processes. */
166
166
/* the semaphore is shared by keeping it in the shared memory segment */
167
167
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 )
171
169
sm_data -> sem_name = (char * ) malloc ( sizeof (char ) * (strlen (filename_basename )+ 32 ) );
172
170
sprintf (sm_data -> sem_name ,"OMPIO_sharedfp_sem_%s" ,filename_basename );
173
171
174
172
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 ){
175
176
#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
+ }
198
193
}else {
199
194
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 ;
205
200
}
206
201
207
202
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)
218
213
struct mca_sharedfp_sm_data * file_data = NULL ;
219
214
220
215
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
+ }
224
219
return OMPI_SUCCESS ;
225
220
}
226
221
sh = fh -> f_sharedfp_data ;
@@ -236,14 +231,14 @@ int mca_sharedfp_sm_file_close (mca_io_ompio_file_t *fh)
236
231
/*Close sm handle*/
237
232
if (file_data -> sm_offset_ptr ) {
238
233
/* 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 );
244
239
#endif
245
240
/*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 ));
247
242
/*Q: Do we need to delete the file? */
248
243
remove (file_data -> sm_filename );
249
244
}
0 commit comments