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
@@ -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
@@ -139,21 +140,21 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
139140
140141 /*TODO: is it necessary to write to the file first?*/
141142 if ( 0 == rank ){
142- memset ( & sm_offset , 0 , sizeof (struct mca_sharedfp_sm_offset ));
143- write ( sm_fd , & sm_offset , sizeof (struct mca_sharedfp_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 ));
144145 }
145146 comm -> c_coll .coll_barrier (comm , comm -> c_coll .coll_barrier_module );
146147
147148 /*the file has been written to, now we can map*/
148149 sm_offset_ptr = mmap (NULL , sizeof (struct mca_sharedfp_sm_offset ), PROT_READ | PROT_WRITE ,
149- MAP_SHARED , sm_fd , 0 );
150+ MAP_SHARED , sm_fd , 0 );
150151
151152 close (sm_fd );
152153
153154 if ( sm_offset_ptr == MAP_FAILED ){
154- err = OMPI_ERROR ;
155- printf ("mca_sharedfp_sm_file_open: Error, unable to mmap file: %s\n" ,sm_filename );
156- 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 ));
157158 free (sm_filename );
158159 free (sm_data );
159160 free (sh );
@@ -170,37 +171,32 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
170171
171172 if ( (sm_data -> mutex = sem_open (sm_data -> sem_name , O_CREAT , 0644 , 1 )) != SEM_FAILED ) {
172173#elif defined(HAVE_SEM_INIT)
174+ sm_data -> mutex = & sm_offset_ptr -> mutex ;
173175 if (sem_init (& sm_offset_ptr -> mutex , 1 , 1 ) != -1 ){
174176#endif
175- /*If opening was successful*/
176- /*Store the new file handle*/
177- sm_data -> sm_offset_ptr = sm_offset_ptr ;
178- /* Assign the sm_data to sh->selected_module_data*/
179- sh -> selected_module_data = sm_data ;
180- /*remember the shared file handle*/
181- fh -> f_sharedfp_data = sh ;
182-
183- /*write initial zero*/
184- if (rank == 0 ){
185- MPI_Offset position = 0 ;
186-
187- #if defined(HAVE_SEM_OPEN )
188- sem_wait (sm_data -> mutex );
189- sm_offset_ptr -> offset = position ;
190- sem_post (sm_data -> mutex );
191- #elif defined(HAVE_SEM_INIT )
192- sem_wait (& sm_offset_ptr -> mutex );
193- sm_offset_ptr -> offset = position ;
194- sem_post (& sm_offset_ptr -> mutex );
195- #endif
196- }
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+ }
197193 }else {
198194 free (sm_filename );
199- free (sm_data );
200- free (sh );
201- free (shfileHandle );
195+ free (sm_data );
196+ free (sh );
197+ free (shfileHandle );
202198 munmap (sm_offset_ptr , sizeof (struct mca_sharedfp_sm_offset ));
203- err = OMPI_ERROR ;
199+ err = OMPI_ERROR ;
204200 }
205201
206202 comm -> c_coll .coll_barrier (comm , comm -> c_coll .coll_barrier_module );
@@ -217,9 +213,9 @@ int mca_sharedfp_sm_file_close (mca_io_ompio_file_t *fh)
217213 struct mca_sharedfp_sm_data * file_data = NULL ;
218214
219215 if ( NULL == fh -> f_sharedfp_data ){
220- if ( mca_sharedfp_sm_verbose ) {
221- printf ("sharedfp_sm_file_close: shared file pointer structure not initialized\n" );
222- }
216+ if ( mca_sharedfp_sm_verbose ) {
217+ printf ("sharedfp_sm_file_close: shared file pointer structure not initialized\n" );
218+ }
223219 return OMPI_SUCCESS ;
224220 }
225221 sh = fh -> f_sharedfp_data ;
@@ -236,10 +232,10 @@ int mca_sharedfp_sm_file_close (mca_io_ompio_file_t *fh)
236232 if (file_data -> sm_offset_ptr ) {
237233 /* destroy semaphore */
238234#if defined(HAVE_SEM_OPEN )
239- sem_unlink (file_data -> sem_name );
240- free (file_data -> sem_name );
235+ sem_unlink (file_data -> sem_name );
236+ free (file_data -> sem_name );
241237#elif defined(HAVE_SEM_INIT )
242- sem_destroy (& file_data -> sm_offset_ptr -> mutex );
238+ sem_destroy (& file_data -> sm_offset_ptr -> mutex );
243239#endif
244240 /*Release the shared memory segment.*/
245241 munmap (file_data -> sm_offset_ptr ,sizeof (struct mca_sharedfp_sm_offset ));
0 commit comments