1 try:
2 from rsf.cluster import *
3 cluster = True
4 except:
5 from rsf.proj import *
6 cluster = False
7 import os
8
9
11 numThreads = int(os.environ.get('OMP_NUM_THREADS','8'))
12 if nodes:
13 return nodes*numThreads
14 try:
15 nodefile = os.environ['PBS_NODEFILE']
16 ff = open(nodefile,'r')
17 nodes = ff.readlines()
18 ff.close()
19 unique = []
20 for node in nodes:
21 if node not in unique:
22 unique.append(node)
23 return len(unique)*numThreads
24 except:
25 if single:
26 return 1
27 else:
28 return numThreads
29
30 -def _find(np,command,custom=''):
31 ''' Find the mpiexec command, and the command to execute '''
32 return '%s -np %d %s %s' % (WhereIs('mpiexec'),np,custom,WhereIs(command))
33
34
35 -def encode(encodings,shotGathers,encoding,
36 np, eprefix,dprefix,mpi=None,time=None,nodes=None,ppn=None,mpiopts=None):
37 '''
38 encode using sfmpiencode.
39
40 '''
41
42 if not '.rsf' in eprefix: eprefix += '.rsf'
43
44 if not '.rsf' in dprefix: dprefix += '.rsf'
45
46 shotGathers.insert(0,encoding)
47
48 if mpi:
49 Flow(encodings,shotGathers,
50 '''
51 sfmpiencode
52 ''' +
53 '''eprefix='''+eprefix+''' dprefix=''' + dprefix +
54 '''
55 encode=${SOURCES[0]}
56 verb=y
57 ''',mpi=True,np=np,nodes=nodes,time=time,ppn=ppn,mpiopts=mpiopts)
58 else:
59 Flow(encodings,shotGathers,
60 '''
61 %s
62 ''' % _find(np,'sfmpiencode','--bynode') +
63 '''eprefix='''+eprefix+''' dprefix=''' + dprefix +
64 '''
65 encode=${SOURCES[0]}
66 verb=y
67 ''')
68
69 -def gridandencode(encodings, shotGathers, encoding,
70 np,
71 eprefix, dprefix,
72 nx,ox,dx,ny,oy,dy,custom,
73 mpi=None,time=None,nodes=None,ppn=None,mpiopts=None):
74 ''' encode using sfbigmpiencode
75 encodings - list of produced encoding files
76 shotGathers - lsit of shotgathers to encode
77 encoding - encoding produced by sfencodemaker
78 np - number of processes to use
79 eprefix - encoding prefix
80 dprefix - data prefix
81 nx,ox,dx,ny,oy,dy - output coordinates for encodings
82 '''
83
84 if not '.rsf' in eprefix:
85 eprefix +='.rsf'
86 if not '.rsf' in dprefix:
87 dprefix +='.rsf'
88 shotGathers.insert(0,encoding)
89 if mpi :
90 Flow(encodings, shotGathers,
91 '''
92 sfbigmpiencode
93 ''' +
94 ''' eprefix=''' + eprefix +
95 ''' dprefix=''' + dprefix +
96 '''
97 encode=${SOURCES[0]}
98 nx=%d ox=%f dx=%f
99 ny=%d oy=%f dy=%f
100 ''' % (nx,ox,dx,ny,oy,dy), mpi=True,time=time,nodes=nodes,ppn=ppn,mpiopts=mpiopts)
101 else:
102 Flow(encodings, shotGathers,
103 '''
104 %s
105 ''' % (_find(np,'sfbigmpiencode',custom)) +
106 ''' eprefix=''' + eprefix +
107 ''' dprefix=''' + dprefix +
108 '''
109 encode=${SOURCES[0]}
110 nx=%d ox=%f dx=%f
111 ny=%d oy=%f dy=%f
112 ''' % (nx,ox,dx,ny,oy,dy) ,stdin=0, stdout=-1)
113
114 -def gridandstack(stack,files,np,
115 fprefix,
116 nx,ox,dx,
117 ny,oy,dy,
118 nz,oz,dz,
119 nf=None,of=None,jf=None,
120 shots=None,
121 mpi=None,time=None,nodes=None,ppn=None,mpiopts=None):
122 ''' stack files using sfbigencode, does not require files
123 to be on the same cube, will relocate them in the cube
124
125 stack - output file
126 files - input files
127 fprefix - input file prefix (dprefix)
128 oprefix - output file prefix (eprefix)
129 nx,ox,dx,ny,oy,dy - output stacked file dimensions
130 either specify shots or nf,of,jf:
131 shots - list of shot indices to be put into a file
132 nf,of,jf - number of files in sequential order
133 '''
134
135 nfiles = len(files)
136
137 oprefix=str(stack)
138
139 if not '.rsf' in fprefix:
140 fprefix += '.rsf'
141 if not '.rsf' in oprefix:
142 oprefix += '.rsf'
143
144 if shots:
145 shotfile = stack+'-shots'
146 Flow(shotfile,None,'points type=i out=${TARGETS[0]} x=%s' % reduce(lambda x,y: str(x)+','+str(y),shots))
147
148 shotfile += '.rsf'
149 files.append(shotfile)
150 if mpi:
151 Flow(stack,files,
152 '''
153 sfbigmpistack
154 ''' +
155 '''
156 nx=%d ny=%d nz=%d
157 ox=%f oy=%f oz=%d
158 dx=%f dy=%f dz=%f
159 shots="%s"
160 verb=y
161 ''' % (nx,ny,nz,ox,oy,oz,dx,dy,dz,shotfile) +
162 '''
163 prefix="'''+fprefix+'''" oname="'''+oprefix+'''"''',
164 mpi=True,nodes=nodes,ppn=ppn,np=np,mpiopts=mpiopts,time=time)
165 else:
166 Flow(stack,files,
167 '''
168 %s
169 ''' % (_find(np,'sfbigmpistack')) +
170 '''
171 nx=%d ny=%d nz=%d
172 ox=%f oy=%f oz=%d
173 dx=%f dy=%f dz=%f
174 shots="%s"
175 verb=y
176 ''' % (nx,ny,nz,ox,oy,oz,dx,dy,dz,shotfile) +
177 '''
178 prefix="'''+fprefix+'''" oname="'''+oprefix+'''"''',stdin=0,stdout=-1)
179
180 else:
181 if (not of) or (not jf) or (not nf):
182 raise Exception('must specify either shots or nf,of,jf')
183
184 if not mpi:
185 Flow(stack,files,
186 '''
187 %s
188 ''' % (_find(np,'sfbigmpistack')) +
189 '''
190 nx=%d ny=%d nz=%d
191 ox=%f oy=%f oz=%d
192 dx=%f dy=%f dz=%f
193 nf=%d of=%d jf=%d
194 ''' % (nx,ny,nz,ox,oy,oz,dx,dy,dz,nf,of,jf) +
195 '''
196 prefix="'''+fprefix+'''" oname="'''+oprefix+'''"''',stdin=0,stdout=-1)
197 else:
198 Flow(stack,files,
199 '''
200 %s
201 ''' % ('sfbigmpistack') +
202 '''
203 nx=%d ny=%d nz=%d
204 ox=%f oy=%f oz=%d
205 dx=%f dy=%f dz=%f
206 nf=%d of=%d jf=%d
207 ''' % (nx,ny,nz,ox,oy,oz,dx,dy,dz,nf,of,jf) +
208 '''
209 prefix="'''+fprefix+'''" oname="'''+oprefix+'''"''',
210 mpi=True,ppn=ppn,nodes=nodes,mpiopts=mpiopts,time=time,np=np)
211
212 -def stack(stack,np,fprefix,files=None,nf=None,of=None,jf=None,shots=None,mpi=None,time=None,ppn=None,nodes=None,mpiopts=None):
213 ''' stack files using sfmpistack
214
215 stack - output file
216 np - number of processes
217 fprefix - input file name prefix
218 nf - number of files
219 of - origin of files
220 jf - delta of files
221 see self-doc for more info
222 '''
223
224
225
226 if not '.rsf' in fprefix:
227 fprefix +='.rsf'
228 oname = stack
229 if not '.rsf' in oname:
230 oname += '.rsf'
231
232 if shots:
233 Flow(stack+'-shots',None,
234 '''
235 points type=i verb=y x=%s
236 out=${TARGETS[0]}
237 ''' % (','.join([str(shot) for shot in shots])))
238
239 else:
240 filerange = range(of,of+nf*jf,jf)
241
242 files = [ fprefix % f for f in filerange]
243
244 if mpi:
245 if shots:
246 files.insert(0,stack+'-shots')
247 Flow(stack,files,
248 '''
249 sfmpistack shots=${SOURCES[0]}
250 ''' +
251 ''' prefix="'''+fprefix +
252 '''" oname="'''+oname+'''"''',
253 mpi=True,np=np,time=time,
254 nodes=nodes,ppn=ppn,mpiopts=mpiopts)
255
256 elif nf and of and jf:
257 Flow(stack,files,
258 '''
259 sfmpistack
260 nf=%d
261 of=%d
262 jf=%d
263 seq=y
264 ''' % (nf,of,jf) +
265 ''' prefix="'''+fprefix +
266 '''" oname="'''+oname+'''"''',
267 mpi=True,np=np,time=time,
268 nodes=nodes,ppn=ppn,mpiopts=mpiopts)
269 elif files:
270 Flow(stack,files,
271 '''
272 sfmpistack
273 ''' + ' '.join(files) +
274 ''' prefix="'''+fprefix +
275 '''" oname="'''+oname+'''"''',
276 mpi=True,np=np,time=time,
277 nodes=nodes,ppn=ppn,mpiopts=mpiopts)
278
279 else:
280 Flow(stack,files,
281 '''
282 %s
283 nf=%d
284 of=%d
285 jf=%d
286 seq=y
287 ''' % (_find(np,'sfmpistack'),nf,of,jf) +
288 ''' prefix="'''+fprefix + '''" oname="'''+oname+'''"''',stdin=0, stdout=-1)
289