This source file includes following definitions.
- mca_sharedfp_sm_seek
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include "ompi_config.h"
25 #include "sharedfp_sm.h"
26
27 #include "mpi.h"
28 #include "ompi/constants.h"
29 #include "ompi/mca/sharedfp/sharedfp.h"
30 #include "ompi/mca/sharedfp/base/base.h"
31
32
33 #include <semaphore.h>
34
35 int
36 mca_sharedfp_sm_seek (ompio_file_t *fh,
37 OMPI_MPI_OFFSET_TYPE off, int whence)
38 {
39 int status=0;
40 OMPI_MPI_OFFSET_TYPE offset, end_position=0;
41 int ret = OMPI_SUCCESS;
42 struct mca_sharedfp_base_data_t *sh = NULL;
43 struct mca_sharedfp_sm_data * sm_data = NULL;
44 struct mca_sharedfp_sm_offset * sm_offset_ptr = NULL;
45
46 if( NULL == fh->f_sharedfp_data ) {
47 opal_output(ompi_sharedfp_base_framework.framework_output,
48 "sharedfp_sm_seek: module not initialized \n");
49 return OMPI_ERROR;
50 }
51
52 sh = fh->f_sharedfp_data;
53 offset = off * fh->f_etype_size;
54
55 if( 0 == fh->f_rank ){
56 if ( MPI_SEEK_SET == whence){
57
58 if ( offset < 0){
59 opal_output(0,"sharedfp_sm_seek - MPI_SEEK_SET, offset must be > 0, got offset=%lld.\n",offset);
60 ret = -1;
61 }
62 if ( mca_sharedfp_sm_verbose ) {
63 opal_output(ompi_sharedfp_base_framework.framework_output,
64 "sharedfp_sm_seek: MPI_SEEK_SET new_offset=%lld\n",offset);
65 }
66 }
67 else if( MPI_SEEK_CUR == whence){
68 OMPI_MPI_OFFSET_TYPE current_position;
69 ret = mca_sharedfp_sm_get_position ( fh, ¤t_position);
70 if ( mca_sharedfp_sm_verbose ) {
71 opal_output(ompi_sharedfp_base_framework.framework_output,
72 "sharedfp_sm_seek: MPI_SEEK_CUR: curr=%lld, offset=%lld, call status=%d\n",
73 current_position,offset,status);
74 }
75 offset = current_position + offset;
76 if ( mca_sharedfp_sm_verbose ) {
77 opal_output(ompi_sharedfp_base_framework.framework_output,
78 "sharedfp_sm_seek: MPI_SEEK_CUR: new_offset=%lld\n",offset);
79 }
80 if(offset < 0){
81 opal_output(0,"sharedfp_sm_seek - MPI_SEEK_CURE, offset must be > 0, got offset=%lld.\n",offset);
82 ret = -1;
83 }
84 }
85 else if( MPI_SEEK_END == whence){
86 end_position=0;
87 mca_common_ompio_file_get_size(fh,&end_position);
88
89 offset = end_position + offset;
90 if ( mca_sharedfp_sm_verbose ) {
91 opal_output(ompi_sharedfp_base_framework.framework_output,
92 "sharedfp_sm_seek: MPI_SEEK_END: file_get_size=%lld\n",end_position);
93 }
94 if(offset < 0){
95 opal_output(0,"sharedfp_sm_seek - MPI_SEEK_CUR, offset must be > 0, got offset=%lld.\n",offset);
96 ret = -1;
97 }
98 }
99 else {
100 opal_output(0,"sharedfp_sm_seek - whence=%i is not supported\n",whence);
101 ret = -1;
102 }
103
104
105
106
107 sm_data = sh->selected_module_data;
108 sm_offset_ptr = sm_data->sm_offset_ptr;
109
110
111
112
113 if ( mca_sharedfp_sm_verbose ) {
114 opal_output(ompi_sharedfp_base_framework.framework_output,
115 "sharedfp_sm_seek: Aquiring lock, rank=%d...",fh->f_rank); fflush(stdout);
116 }
117
118
119 sm_offset_ptr = sm_data->sm_offset_ptr;
120
121 sem_wait(sm_data->mutex);
122
123 if ( mca_sharedfp_sm_verbose ) {
124 opal_output(ompi_sharedfp_base_framework.framework_output,
125 "sharedfp_sm_seek: Success! Acquired sm lock.for rank=%d\n",fh->f_rank);
126 }
127 sm_offset_ptr->offset=offset;
128 if ( mca_sharedfp_sm_verbose ) {
129 opal_output(ompi_sharedfp_base_framework.framework_output,
130 "sharedfp_sm_seek: Releasing sm lock...rank=%d",fh->f_rank); fflush(stdout);
131 }
132 sem_post(sm_data->mutex);
133 }
134
135
136
137
138 fh->f_comm->c_coll->coll_barrier ( fh->f_comm, fh->f_comm->c_coll->coll_barrier_module );
139
140 return ret;
141 }