-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPIFileHintModule.f90
286 lines (229 loc) · 7.48 KB
/
MPIFileHintModule.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
! ____ _ __ ____ __ ____
! / __/___(_) / ___ ____/ __ \__ _____ ___ / /_ / _/__ ____
! _\ \/ __/ / _ \/ -_) __/ /_/ / // / -_|_-</ __/ _/ // _ \/ __/
! /___/\__/_/_.__/\__/_/ \___\_\_,_/\__/___/\__/ /___/_//_/\__(_)
!
!
! Copyright 2010 SciberQuest Inc.
!
! No permission is granted to reproduce this software.
!
! This is experimental software and is provided ‘‘as is’’, with no
! warranties of any kind whatsoever, no support, no promise of updates,
! or printed documentation.
!==============================================================================
!==============================================================================
! Codes for manipulating MPI_Info
module MPIFileHintModule
use mpi
use StringModule
!----------------------------------------------------------------------------
! generic type conversion for mpi hints (always strings)
interface MPIFileHintSet
module procedure MPIFileHintSetChar
module procedure MPIFileHintSetInt
module procedure MPIFileHintSetBool
module procedure MPIFileHintSetBoolTriState
end interface
interface MPIFileHintGet
module procedure MPIFileHintGetInt
module procedure MPIFileHintGetStr
end interface
interface MPIFileHintStream
module procedure MPIFileHintStreamChar
module procedure MPIFileHintStreamString
end interface
! !----------------------------------------------------------------------------
! ! generic interface printing file hints
! interface MPIFileHintWrite
! procedure MPIFileHintWriteString
! procedure MPIFileHintWriteUnit
! end interface
contains
!------------------------------------------------------------------------------
! Sets the hint to tString if lvalue is .true., otherwise fString
subroutine MPIFileHintSetBoolTriState( &
info, &
key, &
value, &
tString, &
fString, &
oString, &
iErr)
implicit none
integer info
character(len=*) :: key
character(len=*) :: tString,fString,oString
integer value
integer iErr
iErr=0
select case (value)
case (0)
call MPIFileHintSet(info,key,fString,iErr)
case (1)
call MPIFileHintSet(info,key,tString,iErr)
case (2)
call MPIFileHintSet(info,key,oString,iErr)
case default
write(0,*)"Error: invalid value in FileHintSetBoolTriState."
iErr=1
end select
end subroutine
!------------------------------------------------------------------------------
! Sets the hint to tString if lvalue is .true., otherwise fString
subroutine MPIFileHintSetBool(info,key,lvalue,tString,fString,iErr)
implicit none
integer info
character(len=*) :: key
character(len=*) :: tString,fString
logical lvalue
integer iErr
iErr=0
if (lvalue.eqv..true.) then
call MPIFileHintSet(info,key,tString,iErr)
else
call MPIFileHintSet(info,key,fString,iErr)
end if
end subroutine
!------------------------------------------------------------------------------
! Sets the hint from aan integer value
subroutine MPIFileHintSetInt(info,key,iValue,iErr)
implicit none
integer info
character(len=*) key
character(len=15) value
integer iValue
integer iErr
iErr=0
write(value,'(I15)')iValue
call MPIFileHintSet(info,key,trim(value),iErr)
end subroutine
!------------------------------------------------------------------------------
! Set hint name,value pair on info. If info is set to MPI_INFO_NULL
! upon entry then a new info object is created.
subroutine MPIFileHintSetChar(info,key,value,iErr)
implicit none
integer info
character(len=*) key,value
integer iErr
iErr=0
if (info.eq.MPI_INFO_NULL) then
call MPI_Info_create(info,iErr)
end if
call MPI_Info_set(info,key,value,iErr)
end subroutine
! !------------------------------------------------------------------------------
! ! Write the hints to a the given open file unit.
! subroutine MPIFileHintWrite(info,unitNo,iErr)
! implicit none
! integer info
! integer unitNo
! integer iErr
! character(len=256) eStr
! character(len=1024) buffer
!
! iErr=0
!
! call MPIFileHintWriteString(info,buffer,iErr)
! if (iErr.ne.0) return
!
! write(
! unit=unitNo,
! fmt='(A)',
! iostat=iErr,
! iomsg=eStr)
! MPIFileHintStream(
! if (iErr.ne.0) then
! write(0,*)"Error: ",trim(eStr)
! return
! end if
!
! end subroutine
!------------------------------------------------------------------------------
! serializes the given hints into a string one per line.
function MPIFileHintStreamChar(info) result(oBuffer)
implicit none
character(len=4096) oBuffer
integer info, nKeys
character(len=128) key
character(len=256) value
character(len=512) keyValueBuf
character(len=512) iBuffer
logical keyDefined
integer i
integer iErr
iErr=0
oBuffer=""
call MPI_Info_get_nkeys(info,nKeys,iErr)
do i=1,nKeys
call MPI_Info_get_nthkey(info,i-1,key,iErr)
call MPI_Info_get(info,key,256,value,keyDefined,iErr)
if (iErr.eq.0) then
keyValueBuf=StringNameValue(key,value)
else
write(keyValueBuf,'(4A)')"Error: Buffer too small. ",trim(key),char(10)
write(0,*)keyValueBuf
endif
iBuffer=""
iBuffer=trim(oBuffer)//trim(keyValueBuf)
oBuffer=trim(iBuffer)
end do
! call MPI_Info_free(info,iErr)
end function
!------------------------------------------------------------------------------
! serializes the given hints intoa string one per line.
subroutine MPIFileHintStreamString(info,str)
implicit none
integer info, nKeys
type(String) str
character(len=128) key
character(len=256) value
character(len=512) keyValueBuf
logical keyDefined
integer i
integer iErr
iErr=0
call MPI_Info_get_nkeys(info,nKeys,iErr)
do i=1,nKeys
call MPI_Info_get_nthkey(info,i-1,key,iErr)
call MPI_Info_get(info,key,256,value,keyDefined,iErr)
if (iErr.eq.0) then
keyValueBuf=StringNameValue(key,value)
else
write(keyValueBuf,'(4A)')"Error: Buffer too small. ",trim(key),char(10)
write(0,*)keyValueBuf
endif
call StringAppend(str,keyValueBuf)
end do
! call MPI_Info_free(info,iErr)
end subroutine
!----------------------------------------------------------------------------
subroutine MPIFileHintGetInt(info,key,value,iErr)
integer info
character(*) key
integer value
character(256) valueStr
integer iErr
logical keyDefined
call MPI_Info_get(info,key,256,valueStr,keyDefined,iErr)
if ((.not.keyDefined).or.(iErr.ne.0)) then
write(0,*)"Error: Failed to get value for key ",trim(key),"."
return
endif
read(valueStr,'(i10)')value
end subroutine
!----------------------------------------------------------------------------
subroutine MPIFileHintGetStr(info,key,value,iErr)
integer info
character(*) key
character(*) value
integer valueLen
integer iErr
logical keyDefined
valueLen=len(value)
call MPI_Info_get(info,key,valueLen,value,keyDefined,iErr)
if (.not.keyDefined) then
write(0,*)"Error: Key ",trim(key)," is undefined."
endif
end subroutine
end module