HPCToolkit
make-wrappers.py
Go to the documentation of this file.
1 #!/usr/local/bin/python
2 # -*- python -*-
3 #
4 # HPCToolkit MPI Profiler
5 # this script is adapted from mpiP MPI Profiler ( http://mpip.sourceforge.net/ )
6 #
7 # Please see COPYRIGHT AND LICENSE information at the end of this file.
8 #
9 #
10 # make-wrappers.py -- parse the mpi prototype file and generate a
11 # series of output files, which include the wrappers for profiling
12 # layer and other data structures.
13 #
14 # $Id: make-wrappers.py 442 2010-03-03 17:18:04Z chcham $
15 #
16 
17 import sys
18 import string
19 import os
20 import copy
21 import re
22 import time
23 import getopt
24 import socket
25 import pdb
26 
27 cnt = 0
28 fdict = {}
29 lastFunction = "NULL"
30 verbose = 0
31 baseID = 1000
32 
33 messParamDict = {
34 
35  ( "MPI_Allgather", "sendcount"):1,
36  ( "MPI_Allgather", "sendtype"):2,
37  ( "MPI_Allgatherv", "sendcount"):1,
38  ( "MPI_Allgatherv", "sendtype"):2,
39  ( "MPI_Allreduce", "count"):1,
40  ( "MPI_Allreduce", "datatype"):2,
41  ( "MPI_Alltoall", "sendcount"):1,
42  ( "MPI_Alltoall", "sendtype"):2,
43  ( "MPI_Bcast", "count"):1,
44  ( "MPI_Bcast", "datatype"):2,
45  ( "MPI_Bsend", "count"):1,
46  ( "MPI_Bsend", "datatype"):2,
47  ( "MPI_Gather", "sendcnt"):1,
48  ( "MPI_Gather", "sendtype"):2,
49  ( "MPI_Gatherv", "sendcnt"):1,
50  ( "MPI_Gatherv", "sendtype"):2,
51  ( "MPI_Ibsend", "count"):1,
52  ( "MPI_Ibsend", "datatype"):2,
53  ( "MPI_Irecv", "count"):1,
54  ( "MPI_Irecv", "datatype"):2,
55  ( "MPI_Irsend", "count"):1,
56  ( "MPI_Irsend", "datatype"):2,
57  ( "MPI_Isend", "count"):1,
58  ( "MPI_Isend", "datatype"):2,
59  ( "MPI_Issend", "count"):1,
60  ( "MPI_Issend", "datatype"):2,
61  ( "MPI_Recv", "count"):1,
62  ( "MPI_Recv", "datatype"):2,
63  ( "MPI_Reduce", "count"):1,
64  ( "MPI_Reduce", "datatype"):2,
65  ( "MPI_Rsend", "count"):1,
66  ( "MPI_Rsend", "datatype"):2,
67  ( "MPI_Scan", "count"):1,
68  ( "MPI_Scan", "datatype"):2,
69  ( "MPI_Scatter", "sendcnt"):1,
70  ( "MPI_Scatter", "sendtype"):2,
71  ( "MPI_Send", "count"):1,
72  ( "MPI_Send", "datatype"):2,
73  ( "MPI_Sendrecv", "sendcount"):1,
74  ( "MPI_Sendrecv", "sendtype"):2,
75  ( "MPI_Sendrecv_replace", "count"):1,
76  ( "MPI_Sendrecv_replace", "datatype"):2,
77  ( "MPI_Ssend", "count"):1,
78  ( "MPI_Ssend", "datatype"):2
79  }
80 
81 ioParamDict = {
82 
83  ( "MPI_File_read", "count"):1,
84  ( "MPI_File_read", "datatype"):2,
85  ( "MPI_File_read_all", "count"):1,
86  ( "MPI_File_read_all", "datatype"):2,
87  ( "MPI_File_read_at", "count"):1,
88  ( "MPI_File_read_at", "datatype"):2,
89  ( "MPI_File_write", "count"):1,
90  ( "MPI_File_write", "datatype"):2,
91  ( "MPI_File_write_all", "count"):1,
92  ( "MPI_File_write_all", "datatype"):2,
93  ( "MPI_File_write_at", "count"):1,
94  ( "MPI_File_write_at", "datatype"):2
95  }
96 
97 rmaParamDict = {
98 
99  ( "MPI_Accumulate", "target_count"):1,
100  ( "MPI_Accumulate", "target_datatype"):2,
101  ( "MPI_Get", "origin_count"):1,
102  ( "MPI_Get", "origin_datatype"):2,
103  ( "MPI_Put", "origin_count"):1,
104  ( "MPI_Put", "origin_datatype"):2
105  }
106 
107 noDefineList = [
108  "MPI_Pcontrol"
109  ]
110 
111 opaqueInArgDict = {
112  ("MPI_Abort", "comm"):"MPI_Comm",
113  ("MPI_Accumulate", "origin_datatype"):"MPI_Datatype",
114  ("MPI_Accumulate", "target_datatype"):"MPI_Datatype",
115  ("MPI_Accumulate", "op"):"MPI_Op",
116  ("MPI_Accumulate", "win"):"MPI_Win",
117  ("MPI_Allgather", "comm"):"MPI_Comm",
118  ("MPI_Allgather", "recvtype"):"MPI_Datatype",
119  ("MPI_Allgather", "sendtype"):"MPI_Datatype",
120  ("MPI_Allgatherv", "comm"):"MPI_Comm",
121  ("MPI_Allgatherv", "recvtype"):"MPI_Datatype",
122  ("MPI_Allgatherv", "sendtype"):"MPI_Datatype",
123  ("MPI_Allreduce", "comm"):"MPI_Comm",
124  ("MPI_Allreduce", "datatype"):"MPI_Datatype",
125  ("MPI_Allreduce", "op"):"MPI_Op",
126  ("MPI_Alltoall", "comm"):"MPI_Comm",
127  ("MPI_Alltoall", "recvtype"):"MPI_Datatype",
128  ("MPI_Alltoall", "sendtype"):"MPI_Datatype",
129  ("MPI_Alltoallv", "comm"):"MPI_Comm",
130  ("MPI_Alltoallv", "recvtype"):"MPI_Datatype",
131  ("MPI_Alltoallv", "sendtype"):"MPI_Datatype",
132  ("MPI_Attr_delete", "comm"):"MPI_Comm",
133  ("MPI_Attr_get", "comm"):"MPI_Comm",
134  ("MPI_Attr_put", "comm"):"MPI_Comm",
135  ("MPI_Attr_put", "comm"):"MPI_Comm",
136  ("MPI_Barrier", "comm"):"MPI_Comm",
137  ("MPI_Bcast", "datatype"):"MPI_Datatype",
138  ("MPI_Bcast", "comm"):"MPI_Comm",
139  ("MPI_Bsend", "comm"):"MPI_Comm",
140  ("MPI_Bsend", "datatype"):"MPI_Datatype",
141  ("MPI_Bsend_init", "comm"):"MPI_Comm",
142  ("MPI_Bsend_init", "datatype"):"MPI_Datatype",
143  ("MPI_Cancel", "request"):"MPI_Request",
144  ("MPI_Cart_coords", "comm"):"MPI_Comm",
145  ("MPI_Cart_create", "comm_old"):"MPI_Comm",
146  ("MPI_Cart_get", "comm"):"MPI_Comm",
147  ("MPI_Cart_map", "comm_old"):"MPI_Comm",
148  ("MPI_Cart_rank", "comm"):"MPI_Comm",
149  ("MPI_Cart_shift", "comm"):"MPI_Comm",
150  ("MPI_Cart_sub", "comm"):"MPI_Comm",
151  ("MPI_Cartdim_get", "comm"):"MPI_Comm",
152  ("MPI_Comm_compare", "comm1"):"MPI_Comm",
153  ("MPI_Comm_compare", "comm2"):"MPI_Comm",
154  ("MPI_Comm_create", "comm"):"MPI_Comm",
155  ("MPI_Comm_create", "group"):"MPI_Group",
156  ("MPI_Comm_dup", "comm"):"MPI_Comm",
157  ("MPI_Comm_free", "commp"):"MPI_Comm",
158  ("MPI_Comm_group", "comm"):"MPI_Comm",
159  ("MPI_Comm_rank", "comm"):"MPI_Comm",
160  ("MPI_Comm_remote_group", "comm"):"MPI_Comm",
161  ("MPI_Comm_remote_size", "comm"):"MPI_Comm",
162  ("MPI_Comm_size", "comm"):"MPI_Comm",
163  ("MPI_Comm_split", "comm"):"MPI_Comm",
164  ("MPI_Comm_test_inter", "comm"):"MPI_Comm",
165  ("MPI_Errhandler_get", "comm"):"MPI_Comm",
166  ("MPI_Errhandler_set", "comm"):"MPI_Comm",
167  ("MPI_File_close", "fh"):"MPI_File",
168  ("MPI_File_open", "comm"):"MPI_Comm",
169  ("MPI_File_open", "info"):"MPI_Info",
170  ("MPI_File_preallocate", "fh"):"MPI_File",
171  ("MPI_File_read", "fh"):"MPI_File",
172  ("MPI_File_read", "datatype"):"MPI_Datatype",
173  ("MPI_File_read_all", "fh"):"MPI_File",
174  ("MPI_File_read_all", "datatype"):"MPI_Datatype",
175  ("MPI_File_read_at", "fh"):"MPI_File",
176  ("MPI_File_read_at", "datatype"):"MPI_Datatype",
177  ("MPI_File_seek", "fh"):"MPI_File",
178  ("MPI_File_set_view", "fh"):"MPI_File",
179  ("MPI_File_set_view", "etype"):"MPI_Datatype",
180  ("MPI_File_set_view", "filetype"):"MPI_Datatype",
181  ("MPI_File_set_view", "info"):"MPI_Info",
182  ("MPI_File_write", "fh"):"MPI_File",
183  ("MPI_File_write", "datatype"):"MPI_Datatype",
184  ("MPI_File_write_all", "fh"):"MPI_File",
185  ("MPI_File_write_all", "datatype"):"MPI_Datatype",
186  ("MPI_File_write_at", "fh"):"MPI_File",
187  ("MPI_File_write_at", "datatype"):"MPI_Datatype",
188  ("MPI_Gather", "comm"):"MPI_Comm",
189  ("MPI_Gather", "recvtype"):"MPI_Datatype",
190  ("MPI_Gather", "sendtype"):"MPI_Datatype",
191  ("MPI_Gatherv", "comm"):"MPI_Comm",
192  ("MPI_Gatherv", "recvtype"):"MPI_Datatype",
193  ("MPI_Gatherv", "sendtype"):"MPI_Datatype",
194  ("MPI_Get", "origin_datatype"):"MPI_Datatype",
195  ("MPI_Get", "target_datatype"):"MPI_Datatype",
196  ("MPI_Get", "win"):"MPI_Win",
197  ("MPI_Get_count", "datatype"):"MPI_Datatype",
198  ("MPI_Get_elements", "datatype"):"MPI_Datatype",
199  ("MPI_Graph_create", "comm_old"):"MPI_Comm",
200  ("MPI_Graph_get", "comm"):"MPI_Comm",
201  ("MPI_Graph_map", "comm_old"):"MPI_Comm",
202  ("MPI_Graph_neighbors", "comm"):"MPI_Comm",
203  ("MPI_Graph_neighbors_count", "comm"):"MPI_Comm",
204  ("MPI_Graphdims_get", "comm"):"MPI_Comm",
205  ("MPI_Group_compare", "group1"):"MPI_Group",
206  ("MPI_Group_compare", "group2"):"MPI_Group",
207  ("MPI_Group_difference", "group1"):"MPI_Group",
208  ("MPI_Group_difference", "group2"):"MPI_Group",
209  ("MPI_Group_excl", "group"):"MPI_Group",
210  ("MPI_Group_free", "group"):"MPI_Group",
211  ("MPI_Group_incl", "group"):"MPI_Group",
212  ("MPI_Group_intersection", "group1"):"MPI_Group",
213  ("MPI_Group_intersection", "group2"):"MPI_Group",
214  ("MPI_Group_range_excl", "group"):"MPI_Group",
215  ("MPI_Group_range_incl", "group"):"MPI_Group",
216  ("MPI_Group_rank", "group"):"MPI_Group",
217  ("MPI_Group_size", "group"):"MPI_Group",
218  ("MPI_Group_translate_ranks", "group_a"):"MPI_Group",
219  ("MPI_Group_translate_ranks", "group_b"):"MPI_Group",
220  ("MPI_Group_union", "group1"):"MPI_Group",
221  ("MPI_Group_union", "group2"):"MPI_Group",
222  ("MPI_Ibsend", "comm"):"MPI_Comm",
223  ("MPI_Ibsend", "datatype"):"MPI_Datatype",
224  ("MPI_Intercomm_create", "local_comm"):"MPI_Comm",
225  ("MPI_Intercomm_create", "peer_comm"):"MPI_Comm",
226  ("MPI_Intercomm_merge", "comm"):"MPI_Comm",
227  ("MPI_Iprobe", "comm"):"MPI_Comm",
228  ("MPI_Irecv", "comm"):"MPI_Comm",
229  ("MPI_Irecv", "datatype"):"MPI_Datatype",
230  ("MPI_Irsend", "comm"):"MPI_Comm",
231  ("MPI_Irsend", "datatype"):"MPI_Datatype",
232  ("MPI_Isend", "comm"):"MPI_Comm",
233  ("MPI_Isend", "datatype"):"MPI_Datatype",
234  ("MPI_Issend", "comm"):"MPI_Comm",
235  ("MPI_Issend", "datatype"):"MPI_Datatype",
236  ("MPI_Pack", "comm"):"MPI_Comm",
237  ("MPI_Pack", "datatype"):"MPI_Datatype",
238  ("MPI_Pack_size", "comm"):"MPI_Comm",
239  ("MPI_Pack_size", "datatype"):"MPI_Datatype",
240  ("MPI_Probe", "comm"):"MPI_Comm",
241  ("MPI_Put", "origin_datatype"):"MPI_Datatype",
242  ("MPI_Put", "target_datatype"):"MPI_Datatype",
243  ("MPI_Put", "win"):"MPI_Win",
244  ("MPI_Recv", "comm"):"MPI_Comm",
245  ("MPI_Recv", "datatype"):"MPI_Datatype",
246  ("MPI_Recv_init", "comm"):"MPI_Comm",
247  ("MPI_Recv_init", "datatype"):"MPI_Datatype",
248  ("MPI_Reduce", "comm"):"MPI_Comm",
249  ("MPI_Reduce", "datatype"):"MPI_Datatype",
250  ("MPI_Reduce", "op"):"MPI_Op",
251  ("MPI_Reduce_scatter", "comm"):"MPI_Comm",
252  ("MPI_Reduce_scatter", "datatype"):"MPI_Datatype",
253  ("MPI_Reduce_scatter", "op"):"MPI_Op",
254  ("MPI_Request_free", "request"):"MPI_Request",
255  ("MPI_Rsend", "comm"):"MPI_Comm",
256  ("MPI_Rsend", "datatype"):"MPI_Datatype",
257  ("MPI_Rsend_init", "comm"):"MPI_Comm",
258  ("MPI_Rsend_init", "datatype"):"MPI_Datatype",
259  ("MPI_Scan", "comm"):"MPI_Comm",
260  ("MPI_Scan", "op"):"MPI_Op",
261  ("MPI_Scan", "datatype"):"MPI_Datatype",
262  ("MPI_Scatter", "comm"):"MPI_Comm",
263  ("MPI_Scatter", "recvtype"):"MPI_Datatype",
264  ("MPI_Scatter", "sendtype"):"MPI_Datatype",
265  ("MPI_Scatterv", "comm"):"MPI_Comm",
266  ("MPI_Scatterv", "recvtype"):"MPI_Datatype",
267  ("MPI_Scatterv", "sendtype"):"MPI_Datatype",
268  ("MPI_Send", "comm"):"MPI_Comm",
269  ("MPI_Send", "datatype"):"MPI_Datatype",
270  ("MPI_Send_init", "comm"):"MPI_Comm",
271  ("MPI_Send_init", "datatype"):"MPI_Datatype",
272  ("MPI_Sendrecv", "comm"):"MPI_Comm",
273  ("MPI_Sendrecv", "recvtag"):"MPI_Datatype",
274  ("MPI_Sendrecv", "recvtype"):"MPI_Datatype",
275  ("MPI_Sendrecv", "sendtype"):"MPI_Datatype",
276  ("MPI_Sendrecv_replace", "comm"):"MPI_Comm",
277  ("MPI_Sendrecv_replace", "datatype"):"MPI_Datatype",
278  ("MPI_Ssend", "comm"):"MPI_Comm",
279  ("MPI_Ssend", "datatype"):"MPI_Datatype",
280  ("MPI_Ssend_init", "comm"):"MPI_Comm",
281  ("MPI_Ssend_init", "datatype"):"MPI_Datatype",
282  ("MPI_Start", "request"):"MPI_Request",
283  ("MPI_Startall", "array_of_requests"):"MPI_Request",
284  ("MPI_Test", "request"):"MPI_Request",
285  ("MPI_Testall", "array_of_requests"):"MPI_Request",
286  ("MPI_Testany", "array_of_requests"):"MPI_Request",
287  ("MPI_Testsome", "array_of_requests"):"MPI_Request",
288  ("MPI_Topo_test", "comm"):"MPI_Comm",
289  ("MPI_Type_commit", "datatype"):"MPI_Datatype",
290  ("MPI_Type_contiguous", "oldtype"):"MPI_Datatype",
291  ("MPI_Type_extent", "datatype"):"MPI_Datatype",
292  ("MPI_Type_free", "datatype"):"MPI_Datatype",
293  ("MPI_Type_get_contents", "datatype"):"MPI_Datatype",
294  ("MPI_Type_get_envelope", "datatype"):"MPI_Datatype",
295  ("MPI_Type_hindexed", "oldtype"):"MPI_Datatype",
296  ("MPI_Type_hvector", "oldtype"):"MPI_Datatype",
297  ("MPI_Type_indexed", "oldtype"):"MPI_Datatype",
298  ("MPI_Type_lb", "datatype"):"MPI_Datatype",
299  ("MPI_Type_size", "datatype"):"MPI_Datatype",
300  ("MPI_Type_struct", "array_of_types"):"MPI_Datatype",
301  ("MPI_Type_ub", "datatype"):"MPI_Datatype",
302  ("MPI_Type_vector", "oldtype"):"MPI_Datatype",
303  ("MPI_Unpack", "comm"):"MPI_Comm",
304  ("MPI_Unpack", "datatype"):"MPI_Datatype",
305  ("MPI_Wait", "request"):"MPI_Request",
306  ("MPI_Waitall", "array_of_requests"):"MPI_Request",
307  ("MPI_Waitany", "array_of_requests"):"MPI_Request",
308  ("MPI_Waitsome", "array_of_requests"):"MPI_Request",
309  ("MPI_Win_complete", "win"):"MPI_Win",
310  ("MPI_Win_create", "info"):"MPI_Info",
311  ("MPI_Win_create", "comm"):"MPI_Comm",
312  ("MPI_Win_create", "win"):"MPI_Win",
313  ("MPI_Win_fence", "win"):"MPI_Win",
314  ("MPI_Win_free", "win"):"MPI_Win",
315  ("MPI_Win_get_group", "win"):"MPI_Win",
316  ("MPI_Win_get_group", "group"):"MPI_Group",
317  ("MPI_Win_lock", "win"):"MPI_Win",
318  ("MPI_Win_post", "group"):"MPI_Group",
319  ("MPI_Win_post", "win"):"MPI_Win",
320  ("MPI_Win_start", "group"):"MPI_Group",
321  ("MPI_Win_start", "win"):"MPI_Win",
322  ("MPI_Win_test", "win"):"MPI_Win",
323  ("MPI_Win_unlock", "win"):"MPI_Win",
324  ("MPI_Win_wait", "win"):"MPI_Win"
325 }
326 
327 opaqueOutArgDict = {
328  ("MPI_Bsend_init", "request"):"MPI_Request",
329  ("MPI_Cart_create", "comm_cart"):"MPI_Comm",
330  ("MPI_Cart_sub", "comm_new"):"MPI_Comm",
331  ("MPI_Comm_create", "comm_out"):"MPI_Comm",
332  ("MPI_Comm_dup", "comm_out"):"MPI_Comm",
333  ("MPI_Comm_free", "commp"):"MPI_Comm",
334  ("MPI_Comm_group", "group"):"MPI_Group",
335  ("MPI_Comm_remote_group", "group"):"MPI_Group",
336  ("MPI_Comm_split", "comm_out"):"MPI_Comm",
337  ("MPI_File_close", "fh"):"MPI_File",
338  ("MPI_File_open", "fh"):"MPI_File",
339  ("MPI_Graph_create", "comm_graph"):"MPI_Comm",
340  ("MPI_Group_difference", "group_out"):"MPI_Group",
341  ("MPI_Group_excl", "newgroup"):"MPI_Group",
342  ("MPI_Group_free", "group"):"MPI_Group",
343  ("MPI_Group_incl", "group_out"):"MPI_Group",
344  ("MPI_Group_intersection", "group_out"):"MPI_Group",
345  ("MPI_Group_range_excl", "newgroup"):"MPI_Group",
346  ("MPI_Group_range_incl", "newgroup"):"MPI_Group",
347  ("MPI_Group_union", "group_out"):"MPI_Group",
348  ("MPI_Ibsend", "request"):"MPI_Request",
349  ("MPI_Intercomm_create", "comm_out"):"MPI_Comm",
350  ("MPI_Intercomm_merge", "comm_out"):"MPI_Comm",
351  ("MPI_Irecv", "request"):"MPI_Request",
352  ("MPI_Irsend", "request"):"MPI_Request",
353  ("MPI_Isend", "request"):"MPI_Request",
354  ("MPI_Issend", "request"):"MPI_Request",
355  ("MPI_Op_create", "op"):"MPI_Op",
356  ("MPI_Recv_init", "request"):"MPI_Request",
357  ("MPI_Request_free", "request"):"MPI_Request",
358  ("MPI_Rsend_init", "request"):"MPI_Request",
359  ("MPI_Send_init", "request"):"MPI_Request",
360  ("MPI_Ssend_init", "request"):"MPI_Request",
361  ("MPI_Start", "request"):"MPI_Request",
362  ("MPI_Startall", "array_of_requests"):"MPI_Request",
363  ("MPI_Test", "request"):"MPI_Request",
364  ("MPI_Testall", "array_of_requests"):"MPI_Request",
365  ("MPI_Testany", "array_of_requests"):"MPI_Request",
366  ("MPI_Testsome", "array_of_requests"):"MPI_Request",
367  ("MPI_Type_commit", "datatype"):"MPI_Datatype",
368  ("MPI_Type_contiguous", "newtype"):"MPI_Datatype",
369  ("MPI_Type_free", "datatype"):"MPI_Datatype",
370  ("MPI_Type_get_contents", "array_of_datatypes"):"MPI_Datatype",
371  ("MPI_Type_hindexed", "newtype"):"MPI_Datatype",
372  ("MPI_Type_hvector", "newtype"):"MPI_Datatype",
373  ("MPI_Type_indexed", "newtype"):"MPI_Datatype",
374  ("MPI_Type_struct", "newtype"):"MPI_Datatype",
375  ("MPI_Type_vector", "newtype"):"MPI_Datatype",
376  ("MPI_Wait", "request"):"MPI_Request",
377  ("MPI_Waitall", "array_of_requests"):"MPI_Request",
378  ("MPI_Waitany", "array_of_requests"):"MPI_Request",
379  ("MPI_Waitsome", "array_of_requests"):"MPI_Request"
380 }
381 
382 incrementFortranIndexDict = {
383  ("MPI_Testany"): ("*index", 1),
384  ("MPI_Testsome"): ("array_of_indices", "*count"),
385  ("MPI_Waitany"): ("*index", 1),
386  ("MPI_Waitsome"): ("array_of_indices", "*count")
387  }
388 
389 xlateFortranArrayExceptions = {
390  ("MPI_Testany", "array_of_requests"): ("index"),
391  ("MPI_Waitany", "array_of_requests"): ("index")
392 }
393 
394 
395 class VarDesc:
396  def __init__ (self,name, basetype, pointerLevel, arrayLevel):
397  "initialize a new variable description structure"
398  self.name = name
399  self.basetype = basetype
400  self.pointerLevel = pointerLevel
401  self.arrayLevel = arrayLevel
402  self.recordIt = 0
403 
404 class fdecl:
405  def __init__ (self,name, id, returntype, paramList, paramStr, protoline):
406  "initialize a new function declaration structure"
407  self.name = name
408  self.id = id
409  self.returntype = returntype
410  self.paramList = paramList
411  self.paramStr = paramStr
412  self.paramDict = {}
413  self.protoline = protoline
414  self.wrapperPreList = []
415  self.wrapperPostList = []
416  self.nowrapper = 0
418  self.extrafields = {}
419  self.extrafieldsList = []
420  self.sendCountPname = ""
421  self.sendTypePname = ""
422  self.recvCountPname = ""
423  self.recvTypePname = ""
424  self.ioCountPname = ""
425  self.ioTypePname = ""
426  self.rmaCountPname = ""
427  self.rmaTypePname = ""
428 
430  def __init__ (self,mpiType,varName):
431  "initialize a new Fortran translation structure"
432  self.mpiType = mpiType
433  self.varName = varName
434 
435 
436 def ProcessDirectiveLine(lastFunction, line):
437  tokens = string.split(line)
438  if tokens[0] == "nowrapper":
439  fdict[lastFunction].nowrapper = 1
440  elif tokens[0] == "extrafield":
441  fdict[lastFunction].extrafieldsList.append(tokens[2])
442  fdict[lastFunction].extrafields[tokens[2]] = tokens[1]
443  else:
444  print "Warning: ",lastFunction," unknown directive [",string.strip(line),"]"
445 
446 
447 def ProcessWrapperPreLine(lastFunction, line):
448  #print "Processing wrapper pre [",string.strip(line),"] for ",lastFunction
449  fdict[lastFunction].wrapperPreList.append(line)
450 
451 
452 def ProcessWrapperPostLine(lastFunction, line):
453  #print "Processing wrapper post [",string.strip(line),"] for ",lastFunction
454  fdict[lastFunction].wrapperPostList.append(line)
455 
456 
457 def DumpDict():
458  for i in flist:
459  print i
460  if verbose:
461  print "\tParams\t",fdict[i].paramList
462  if fdict[i].wrapperPreList:
463  print "\tpre\t", fdict[i].wrapperPreList
464  if fdict[i].wrapperPostList:
465  print "\tpost\t", fdict[i].wrapperPostList
466 
467 
468 
472 def SpecialParamRecord(funct,param):
473  global flist
474  global fdict
475  basetype = fdict[funct].paramDict[param].basetype
476  pointerLevel = fdict[funct].paramDict[param].pointerLevel
477  arrayLevel = fdict[funct].paramDict[param].arrayLevel
478 
479  simplePointer = (pointerLevel == 1) and (arrayLevel == 0)
480 
481  if basetype == "MPI_Request" and simplePointer:
482  return 1
483  elif basetype == "MPI_Comm" and simplePointer:
484  return 1
485  elif basetype == "MPI_Datatype" and simplePointer:
486  return 1
487  elif basetype == "MPI_Group" and simplePointer:
488  return 1
489  elif basetype == "MPI_Info" and simplePointer:
490  return 1
491  elif basetype == "int" and simplePointer:
492  return 1
493  else:
494  return 0
495 
496 
497 
498 
502 def ParamDictUpdate(fname):
503  global flist
504  global fdict
505  global messParamDict
506  global ioParamDict
507  global rmaParamDict
508  for p in fdict[fname].paramList:
509 
510  pname = "NULL"
511  basetype = "NULL"
512  pointerLevel = string.count(p,"*")
513  arrayLevel = string.count(p,"[")
514  if (pointerLevel > 0) and (arrayLevel > 0):
515 
516  pname = p[string.rfind(p,"*")+1:string.find(p,"[")]
517  basetype = p[0:string.find(p,"*")]
518  elif pointerLevel > 0:
519 
520  pname = p[string.rfind(p,"*")+1:len(p)]
521  basetype = p[0:string.find(p,"*")]
522  elif arrayLevel > 0:
523 
524  pname = p[string.find(p," "):string.find(p,"[")]
525  basetype = p[0:string.find(p," ")]
526  else:
527 
528  tokens = string.split(p)
529  if len(tokens) == 1:
530 
531  pname = ""
532  basetype = "void"
533  else:
534  pname = string.strip(tokens[1])
535  basetype = string.strip(tokens[0])
536 
537  pname = string.strip(pname)
538  basetype = string.strip(basetype)
539  fdict[fname].paramDict[pname] = VarDesc(pname,basetype,pointerLevel,arrayLevel)
540  fdict[fname].paramConciseList.append(pname)
541 
542  # Identify and assign message size parameters
543  if messParamDict.has_key((fname,pname)):
544  paramMessType = messParamDict[(fname,pname)]
545  if paramMessType == 1:
546  fdict[fname].sendCountPname = pname
547  elif paramMessType == 2:
548  fdict[fname].sendTypePname = pname
549  elif paramMessType == 3:
550  fdict[fname].recvCountPname = pname
551  elif paramMessType == 4:
552  fdict[fname].recvTypePname = pname
553 
554  # Identify and assign io size parameters
555  if ioParamDict.has_key((fname,pname)):
556  paramMessType = ioParamDict[(fname,pname)]
557  if paramMessType == 1:
558  fdict[fname].ioCountPname = pname
559  elif paramMessType == 2:
560  fdict[fname].ioTypePname = pname
561 
562  # Identify and assign rma size parameters
563  if rmaParamDict.has_key((fname,pname)):
564  paramMessType = rmaParamDict[(fname,pname)]
565  if paramMessType == 1:
566  fdict[fname].rmaCountPname = pname
567  elif paramMessType == 2:
568  fdict[fname].rmaTypePname = pname
569 
570  if (fdict[fname].paramDict[pname].pointerLevel == 0) \
571  and (fdict[fname].paramDict[pname].arrayLevel == 0) \
572  and (fdict[fname].paramDict[pname].basetype != "void"):
573  fdict[fname].paramDict[pname].recordIt = 1
574  elif SpecialParamRecord(fname,pname):
575  fdict[fname].paramDict[pname].recordIt = 1
576  else:
577  pass
578 
579  if verbose:
580  #print "\t->",p
581  print "\t",pname, basetype, pointerLevel, arrayLevel
582 
583 
584 
588  # parser states
589  p_start = "start"
590  p_directives = "directives"
591  p_wrapper_pre = "wrapper_pre"
592  p_wrapper_post = "wrapper_post"
593  parserState = p_start
594  global cnt
595  global fdict
596  global flist
597 
598  fcounter = baseID
599 
600  print "-----*----- Parsing input file:",f
601  while 1:
602 
603  rawline = f.readline()
604  if not rawline:
605  break
606  cnt = cnt + 1
607  line = re.sub("\@.*$","",rawline)
608 
609 
610  tokens = string.split(line)
611  if not tokens:
612  continue
613 
614 
615  if (string.find(line,"(") != -1) \
616  and (string.find(line,")") != -1) \
617  and (string.find(line,"MPI_") != -1) \
618  and parserState == p_start:
619 
620  name = tokens[1]
621  retype = tokens[0]
622  lparen = string.index(line,"(")
623  rparen = string.index(line,")")
624  paramstr = line[lparen+1:rparen]
625  paramList = map(string.strip,string.split(paramstr,","))
626  # print cnt, "-->", name, paramList
627  fdict[name] = fdecl(name, fcounter, retype, paramList, paramstr, line)
628  ParamDictUpdate(name)
629  lastFunction = name
630  if verbose:
631  print name
632  else:
633 
634  if tokens[0] == "directives" and parserState != p_directives:
635 
636  parserState = p_directives
637  elif tokens[0] == "directives" and parserState == p_directives:
638 
639  parserState = p_start
640  elif parserState == p_directives:
641 
642  ProcessDirectiveLine(lastFunction, line)
643 
644 
645  elif tokens[0] == "wrapper_pre" and parserState != p_wrapper_pre:
646 
647  parserState = p_wrapper_pre
648  elif tokens[0] == "wrapper_pre" and parserState == p_wrapper_pre:
649 
650  parserState = p_start
651  elif parserState == p_wrapper_pre:
652 
653  ProcessWrapperPreLine(lastFunction, line)
654 
655 
656  elif tokens[0] == "wrapper_post" and parserState != p_wrapper_post:
657 
658  parserState = p_wrapper_post
659  elif tokens[0] == "wrapper_post" and parserState == p_wrapper_post:
660 
661  parserState = p_start
662  elif parserState == p_wrapper_post:
663 
664  ProcessWrapperPostLine(lastFunction, line)
665 
666 
667  else:
668  print "Unknown input line ",cnt, ":", line,
669 
670  flist = fdict.keys()
671  flist.sort()
672  fcounter = baseID
673  for f in flist :
674  fdict[f].id = fcounter
675  if f not in noDefineList:
676  fcounter = fcounter + 1
677  print "-----*----- Parsing completed: ", len(fdict), " functions found."
678 
679 
680 
684  olist = []
685  olist.append("/* " + fname + " */\n")
686  olist.append("/* DO NOT EDIT -- AUTOMATICALLY GENERATED! */\n")
687  olist.append("/* Timestamp: " + time.strftime("%d %B %Y %H:%M", time.localtime(time.time())) + " */\n")
688  olist.append("/* Location: " + socket.gethostname () + " " + os.name + " */\n")
689  olist.append("/* Creator: " + os.environ["LOGNAME"] + " */\n")
690  olist.append("\n")
691  olist.append("\n")
692  return olist
693 
694 
695 
702  global flist
703  global fdict
704 
705  for funct in flist:
706  if verbose:
707  print funct
708  ParamDictUpdate(funct)
709 
710 
711 
715  global flist
716  global fdict
717  print "-----*----- Generating structure files"
718  cwd = os.getcwd()
719  os.chdir(cwd)
720  sname = cwd + "/mpiPi_def.h"
721  g = open(sname, "w")
722  olist = StandardFileHeader(sname)
723 
724  olist.append("\n")
725  olist.append("#define mpiPi_BASE " + str(baseID) + "\n")
726  olist.append("\n")
727 
728  for funct in flist:
729  if funct not in noDefineList:
730  olist.append("#define mpiPi_" + funct + " " + str(fdict[funct].id) + "\n")
731 
732  olist.append("\n\n/* eof */\n")
733  g.writelines(olist)
734  g.close()
735 
736 
737 
741  global flist
742  global fdict
743 
744  print "-----*----- Generating the lookup table"
745  cwd = os.getcwd()
746  os.chdir(cwd)
747  sname = cwd + "/lookup.c"
748  g = open(sname, "w")
749  olist = StandardFileHeader(sname)
750 
751  olist.append("#include \"mpiPi.h\"\n")
752  olist.append("#include \"mpiPi_def.h\"\n")
753  olist.append("\n")
754  olist.append("\n")
755 
756  olist.append("mpiPi_lookup_t mpiPi_lookup [] = {\n")
757 
758  counter = 0
759  for funct in flist:
760  if funct not in noDefineList:
761  if counter < len(flist) \
762  and counter > 0 :
763  olist.append(",\n")
764  olist.append("\t{ mpiPi_" + funct)
765  olist.append(", \"" + funct + "\"")
766  olist.append("}")
767  counter = counter + 1
768 
769  olist.append(",\n\t{0,NULL}};\n")
770 
771  olist.append("\n")
772  olist.append("/* eof */\n")
773  g.writelines(olist)
774  g.close()
775 
776 
777 
781 def CreateWrapper(funct, olist):
782  global fdict
783  global arch
784 
785  if fdict[funct].nowrapper:
786  return
787 
788  if verbose:
789  print "Wrapping ",funct
790 
791  olist.append("\n\n\n/* --------------- " + funct + " --------------- */\n" )
792 
793 
796  olist.append("\n\n" + fdict[funct].returntype + " HPCRUN_MPI_WRAP("
797  + fdict[funct].name + ") (" + fdict[funct].paramStr + "){" )
798  if fdict[funct].wrapperPreList:
799  olist.extend(fdict[funct].wrapperPreList)
800 
801  if ((fdict[funct].sendCountPname != "") or (fdict[funct].recvCountPname != "")):
802  buffcount = fdict[funct].sendCountPname
803  bufftype = fdict[funct].sendTypePname
804 
805  if (fdict[funct].sendCountPname == ""):
806  buffcount = fdict[funct].recvCountPname
807  bufftype = fdict[funct].recvTypePname
808 
809  olist.append( "\n"
810  + "if ( " + fdict[funct].sendTypePname + " != MPI_DATATYPE_NULL ) {\n"
811  + " hpmpi_store_metric(Get_Msg_size(" +buffcount+ ", "+ bufftype + ") );\n"
812  + "} else {\n TMSG(MPI,\"MPI_DATATYPE_NULL encountered. MPI_IN_PLACE not supported.\\n\");\n"
813  + " TMSG(MPI,\"Values for %s may be invalid.\\n\", &(__func__)[7]);\n}\n")
814 
815  olist.append("\nreturn P" + funct + "( " )
816 
817  for i in fdict[funct].paramConciseList:
818  if (fdict[funct].paramDict[i].pointerLevel == 0) \
819  and (fdict[funct].paramDict[i].arrayLevel == 0) \
820  and (fdict[funct].paramDict[i].basetype != "void"):
821  olist.append(" " + i)
822  elif (fdict[funct].paramDict[i].pointerLevel > 0):
823  olist.append(i)
824  elif (fdict[funct].paramDict[i].arrayLevel > 0):
825  olist.append(i)
826  else:
827  print "Warning: passing on arg",i,"in",funct
828  if fdict[funct].paramConciseList.index(i) < len(fdict[funct].paramConciseList) - 1:
829  olist.append(", ")
830 
831  olist.append(" );\n\n" )
832  olist.append("}" + " /* " + funct + " */\n")
833 
834 
835 
838 
839 
840  olist.append("\n\nvoid " + "F77_" + string.upper(funct) + "(" )
841 
842  #================================================================================
843  # In the case where MPI_Fint and and opaque objects such as MPI_Request are not the same size,
844  # we want to use MPI conversion functions.
845  #
846  # The most obvious problem we have encountered is for MPI_Request objects,
847  # but Communicators, Group, Datatype, Op, and File are also possibily problems.
848  #
849  # There are two cases:
850  # 1) A single argument needs to be translated.
851  # 2) An array of objects needs to be allocated and translated.
852  # This only appears necessary for Request and Datatype
853  #
854  # The algorithm for processing Fortran wrapper functions is as follows:
855  # 1. Declare all C variable versions for Fortran arguments.
856  # 2. Allocate any arrays to be used.
857  # 3. Perform any necessary pre-call array and scalar xlation.
858  # 4. Make the function call with appropriate C variables.
859  # 5. Perform any necessary post-call array and scalar xlation.
860  # 6. Free any arrays.
861  #================================================================================
862 
863 
864  xlateVarName = ""
865  xlateVarNames = []
866  xlateTypes = []
867  xlateCount = 0
868  # Input types to translate
869  xlateTargetTypes = [ "MPI_Comm", "MPI_Datatype", "MPI_File", "MPI_Group", "MPI_Info", "MPI_Op", "MPI_Request" ]
870 
871  freelist = []
872 
873  # Iterate through the arguments for this function
874  opaqueFound = 0
875  for i in fdict[funct].paramConciseList:
876 
877  if ( doOpaqueXlate is True and fdict[funct].paramDict[i].basetype in xlateTargetTypes ) :
878 
879  # Verify that there is a Dictionary entry for translating this argument
880  if ( not ( opaqueInArgDict.has_key((funct, i)) or opaqueOutArgDict.has_key((funct, i)) ) ):
881  print "*** Failed to find translation information for " + funct + ":" + i + "\n"
882 
883  opaqueFound = 1
884  # All Fortran opaque object are of type MPI_Fint
885  currBasetype = "MPI_Fint"
886 
887  # Store variable name and type
888  xlateTypes.append(fdict[funct].paramDict[i].basetype)
889  xlateVarNames.append(i)
890 
891  # Try to identify whether array or single value by whether "array" is in the variable name
892  # and add C declaration to declaration list.
893  if ( xlateVarNames[xlateCount].count("array") > 0 ):
894  decl += xlateTypes[xlateCount] + " *c_" + xlateVarNames[xlateCount] + ";\n";
895  else:
896  decl += xlateTypes[xlateCount] + " c_" + xlateVarNames[xlateCount] + ";\n";
897 
898  xlateCount += 1
899  else:
900  # Not translating this variable
901  currBasetype = fdict[funct].paramDict[i].basetype
902 
903  # Add argument to function declaration
904  olist.append(currBasetype + ' ')
905 
906  if (fdict[funct].paramDict[i].pointerLevel == 0) \
907  and (fdict[funct].paramDict[i].arrayLevel == 0) \
908  and (fdict[funct].paramDict[i].basetype != "void"):
909  olist.append(" * ")
910 
911  if (fdict[funct].paramDict[i].pointerLevel > 0):
912  for j in xrange(1,fdict[funct].paramDict[i].pointerLevel+1):
913  olist.append(" *")
914 
915  olist.append(i)
916 
917  if (fdict[funct].paramDict[i].arrayLevel > 0):
918  for x in range(0, fdict[funct].paramDict[i].arrayLevel) :
919  olist.append('[')
920  for x in range(0, fdict[funct].paramDict[i].arrayLevel) :
921  olist.append(']')
922  else:
923  pass
924  if fdict[funct].paramConciseList.index(i) < len(fdict[funct].paramConciseList) - 1:
925  olist.append(", ")
926 
927  # Add ierr argument and declarations to output list
928  olist.append(" , MPI_Fint *ierr)")
929  olist.append("{")
930  olist.append("\n")
931 
932  if fdict[funct].wrapperPreList:
933  olist.extend(fdict[funct].wrapperPreList)
934 
935  if ( 'mips' in arch ) :
936  olist.append("void *saved_ret_addr = __builtin_return_address(0);\n")
937  else :
938  if ( useSetJmp == True ) :
939  olist.append("setjmp (jbuf);\n\n")
940 
941  # Allocate any arrays used for translation
942  for i in range(len(xlateVarNames)) :
943  xlateVarName = xlateVarNames[i]
944  xlateType = xlateTypes[i]
945 
946  # A pretty sketchy way of identifying an array size, but as far as I can tell,
947  # only one array is passed as an argument per function.
948  if ( fdict[funct].paramConciseList.count("count") > 1 ):
949  print "*** Multiple arrays in 1 function!!!!\n";
950 
951  if ( "incount" in fdict[funct].paramConciseList ):
952  countVar = "incount";
953  elif ( "count" in fdict[funct].paramConciseList ):
954  countVar = "count";
955  else:
956  countVar = "max_integers"
957 
958  if ( xlateVarName.count("array") > 0 ):
959  olist.append("c_" + xlateVarName + " = (" + xlateType + "*)malloc(sizeof(" + xlateType + ")*(*" + countVar + "));\n")
960  olist.append("if ( c_" + xlateVarName + " == NULL ) mpiPi_abort(\"Failed to allocate memory in " \
961  + funct + "\");\n")
962  freelist.append("c_"+xlateVarName)
963 
964  # Generate pre-call translation code if necessary by iterating through arguments that
965  # were identified as opaque objects needing translation above
966  for i in range(len(xlateVarNames)) :
967 
968  # Set current argument name and type
969  xlateVarName = xlateVarNames[i]
970  xlateType = xlateTypes[i]
971 
972  # Check for valid function:argument-name entry for pre-call translation.
973  if ( opaqueInArgDict.has_key((funct, xlateVarName)) \
974  and opaqueInArgDict[(funct, xlateVarName)] == xlateType ) :
975 
976  # Datatype translation is the only call where the translation function
977  # doesn't match the argument type.
978  if ( xlateType == "MPI_Datatype" ):
979  xlateFuncType = "MPI_Type"
980  else:
981  xlateFuncType = xlateType
982 
983  if ( xlateVarName.count("array") > 0 ):
984  olist.append("{\n int i; \n")
985  olist.append(" for (i = 0; i < *" + countVar + "; i++) { \n")
986  olist.append(" c_" + xlateVarName + "[i] = " + xlateFuncType + "_f2c(" + xlateVarName + "[i]);\n")
987  olist.append(" }\n}\n")
988  else:
989  olist.append("c_" + xlateVarName + " = " + xlateFuncType + "_f2c(*" + xlateVarName + ");\n")
990 
991  xlateDone = 1
992 
993  # Start generating call to C/Fortran common mpiP wrapper function
994  olist.append("\nint rc = " + funct + "( " )
995  argname = ""
996 
997  # Iterate through mpiP wrapper function arguments, replacing argument with C version where appropriate
998  for i in fdict[funct].paramConciseList:
999  if ( i in xlateVarNames and
1000  ( opaqueInArgDict.has_key((funct, i)) or opaqueOutArgDict.has_key((funct, i))) ):
1001  if ( i.count("array") > 0 ):
1002  argname = "c_" + i;
1003  else:
1004  argname = "&c_" + i;
1005  else:
1006  argname = i
1007 
1008  if (fdict[funct].paramDict[i].pointerLevel == 0) \
1009  and (fdict[funct].paramDict[i].arrayLevel == 0) \
1010  and (fdict[funct].paramDict[i].basetype != "void"):
1011  olist.append("*"+argname)
1012  elif (fdict[funct].paramDict[i].pointerLevel > 0):
1013  olist.append(argname)
1014  elif (fdict[funct].paramDict[i].arrayLevel > 0):
1015  olist.append(argname)
1016  else:
1017  pass
1018 
1019  if fdict[funct].paramConciseList.index(i) < len(fdict[funct].paramConciseList) - 1:
1020  olist.append(", ")
1021 
1022  olist.append(" );\n")
1023  olist.append("*ierr = (MPI_Fint)rc;\n")
1024 
1025  # Generate post-call translation code if necessary
1026  xlateCode = []
1027  xlateDone = 0
1028 
1029  for i in range(len(xlateVarNames)) :
1030 
1031  xlateVarName = xlateVarNames[i]
1032  xlateType = xlateTypes[i]
1033 
1034  if ( opaqueOutArgDict.has_key((funct, xlateVarName)) \
1035  and opaqueOutArgDict[(funct, xlateVarName)] == xlateType ):
1036 
1037  # Datatype translation is the only call where the translation function
1038  # doesn't match the argument type.
1039  if ( xlateType == "MPI_Datatype" ):
1040  xlateFuncType = "MPI_Type"
1041  else:
1042  xlateFuncType = xlateType
1043 
1044  # Generate array or scalar translation code
1045  if ( xlateFortranArrayExceptions.has_key((funct, xlateVarName)) ) :
1046  xlateCode.append(xlateVarName + "[*" + xlateFortranArrayExceptions[(funct,xlateVarName)] + \
1047  "] = " + xlateFuncType + "_c2f(c_" + xlateVarName + \
1048  "[*" + xlateFortranArrayExceptions[(funct, xlateVarName)] + "]);\n")
1049  elif ( xlateVarName.count("array") > 0 ):
1050  xlateCode.append("{\n int i; \n")
1051  xlateCode.append(" for (i = 0; i < *" + countVar + "; i++) { \n")
1052  xlateCode.append(" " + xlateVarName + "[i] = " + xlateFuncType + "_c2f(c_" + xlateVarName + "[i]);\n")
1053  xlateCode.append(" }\n}\n")
1054  else:
1055  xlateCode.append("*" + xlateVarName + " = " + xlateFuncType + "_c2f(c_" + xlateVarName + ");\n")
1056 
1057  xlateDone = 1
1058 
1059  # If appropriate, increment any output indices
1060  if incrementFortranIndexDict.has_key(funct) :
1061  if incrementFortranIndexDict[funct][1] == 1 :
1062  xlateCode.append("if ( " + incrementFortranIndexDict[funct][0] + " >= 0 ) (" + incrementFortranIndexDict[funct][0] + ")++;\n")
1063  else:
1064  xlateCode.append("{ int i; for ( i = 0; i < " + incrementFortranIndexDict[funct][1] + "; i++) " \
1065  + incrementFortranIndexDict[funct][0] + "[i]++;}\n")
1066 
1067  if xlateDone == 1 :
1068  olist.append("if ( rc == MPI_SUCCESS ) { \n")
1069  #print " xlateCode is ", xlateCode
1070  olist.extend(xlateCode)
1071  olist.append("}\n")
1072 
1073  # Free allocated arrays
1074  for freeSym in freelist:
1075  olist.append("free("+freeSym+");\n")
1076 
1077  olist.append("} /* " + string.lower(funct) + " */\n")
1078 
1079  #if ( opaqueFound == 1 and xlateDone == 0 ):
1080  # print "Function " + funct + " not translated!\n"
1081 
1082  print " Wrapped " + funct
1083 
1084 
1086  global flist
1087  global fdict
1088  global arch
1089  global doWeakSymbols
1090 
1091  print "-----*----- Generating profiling wrappers"
1092  cwd = os.getcwd()
1093  os.chdir(cwd)
1094  sname = cwd + "/mpi-overrides.c"
1095  g = open(sname, "w")
1096  olist = StandardFileHeader(sname)
1097  olist.append("#include <assert.h>\n")
1098  olist.append("#include <ucontext.h>\n")
1099  olist.append("#include <stdlib.h>\n")
1100  olist.append("#include <unistd.h>\n")
1101  olist.append("#include <mpi.h>\n")
1102  olist.append("\n/**** local include files****/\n")
1103  olist.append("#include <messages/messages.h>\n")
1104  olist.append("#include <safe-sampling.h>\n")
1105  olist.append("#include <sample_event.h>\n")
1106  olist.append("#include <monitor-exts/monitor_ext.h>\n")
1107  olist.append("#include \"symbols.h\"\n")
1108 
1109  olist.append("\n/**** macros ****/\n")
1110  olist.append("\n#define HPCRUN_MPI_WRAP MONITOR_EXT_WRAP_NAME\n")
1111 
1112  olist.append("\n/**** external functions ****/\n")
1113  olist.append("\nextern int hpcrun_mpi_metric_id();\n")
1114 
1115  olist.append("\n/**** internal private functions ****/\n")
1116  olist.append("\nstatic inline int Get_Msg_size( int count, MPI_Datatype datatype ){\n")
1117  olist.append(" int dsize;\n PMPI_Type_size( datatype, &dsize );\n return count * dsize;\n}\n");
1118  olist.append("\nstatic void hpmpi_store_metric(size_t bytes){\n");
1119  olist.append(" ucontext_t uc;\n");
1120  olist.append(" if (hpcrun_safe_enter()) {\n");
1121  olist.append(" getcontext(&uc);\n");
1122  olist.append(" sample_val_t sampleVal = hpcrun_sample_callpath(&uc, hpcrun_mpi_metric_id(), bytes, 0, 1);\n");
1123  olist.append(" TMSG(MPI, \"sample: %p, bytes: %d\", sampleVal.sample_node, bytes);\n");
1124  olist.append(" hpcrun_safe_exit();\n");
1125  olist.append(" }\n");
1126  olist.append("}\n");
1127 
1128  for funct in flist:
1129  CreateWrapper(funct, olist)
1130  olist.append("\n")
1131  olist.append("\n")
1132  olist.append("/* eof */\n")
1133  g.writelines(olist)
1134  g.close()
1135 
1136 
1137 def GetFortranSymbol(fsymtp, fsym) :
1138  ofsym = ""
1139 
1140  if fsymtp == 'symbol':
1141  ofsym = string.lower(fsym)
1142  elif fsymtp == 'symbol_':
1143  ofsym = string.lower(fsym) + "_"
1144  elif fsymtp == 'symbol__':
1145  ofsym = string.lower(fsym) + "__"
1146  elif fsymtp == 'SYMBOL':
1147  ofsym = string.upper(fsym)
1148  elif fsymtp == 'SYMBOL_':
1149  ofsym = string.upper(fsym) + "_"
1150  elif fsymtp == 'SYMBOL__':
1151  ofsym = string.upper(fsym) + "__"
1152 
1153  return ofsym
1154 
1155 
1157  global flist
1158  global f77symbol
1159 
1160  #
1161  # Generate Weak Symbols
1162  #
1163 
1164  cwd = os.getcwd()
1165  os.chdir(cwd)
1166  sname = cwd + "/weak-symbols.h"
1167  g = open(sname, "w")
1168 
1169  sname = cwd + "/weak-symbols-special.h"
1170  s = open(sname, "w")
1171 
1172  sname = cwd + "/weak-symbols-pcontrol.h"
1173  p = open(sname, "w")
1174 
1175  fmlist = ['symbol', 'symbol_', 'symbol__', 'SYMBOL', 'SYMBOL_', 'SYMBOL__' ]
1176  if f77symbol in fmlist :
1177  fmlist.remove(f77symbol)
1178 
1179  symflist = copy.deepcopy(flist)
1180 
1181  for funct in symflist:
1182  dfunc = GetFortranSymbol(f77symbol, funct)
1183 
1184  for mt in fmlist:
1185  wfunc = GetFortranSymbol(mt, funct)
1186  if funct in [ 'MPI_Init', 'MPI_Init_thread', 'MPI_Finalize'] :
1187  s.write("#pragma weak " + wfunc + " = " + dfunc + "\n")
1188  elif 'Pcontrol' in funct :
1189  p.write("#pragma weak " + wfunc + " = " + dfunc + "\n")
1190  elif fdict[funct].nowrapper == 0 :
1191  g.write("#pragma weak " + wfunc + " = " + dfunc + "\n")
1192 
1193  g.close()
1194  p.close()
1195  s.close()
1196 
1197 
1199  global flist
1200  global f77symbol
1201 
1202  cwd = os.getcwd()
1203  os.chdir(cwd)
1204  sname = cwd + "/symbols.h"
1205 
1206  symflist = copy.deepcopy(flist)
1207  symflist.append('mpipi_get_fortran_argc')
1208  symflist.append('mpipi_get_fortran_arg')
1209 
1210  g = open(sname, "w")
1211  for funct in symflist:
1212  if f77symbol == 'symbol':
1213  f77funct = string.lower(funct)
1214  elif f77symbol == 'symbol_':
1215  f77funct = string.lower(funct) + "_"
1216  elif f77symbol == 'symbol__':
1217  f77funct = string.lower(funct) + "__"
1218  elif f77symbol == 'SYMBOL':
1219  f77funct = string.upper(funct)
1220  elif f77symbol == 'SYMBOL_':
1221  f77funct = string.upper(funct) + "_"
1222  elif f77symbol == 'SYMBOL__':
1223  f77funct = string.upper(funct) + "__"
1224  else:
1225  f77funct = string.lower(funct)
1226 
1227  g.write("#define F77_" + string.upper(funct) + " " + f77funct + "\n")
1228 
1229  g.close()
1230 
1231 def main():
1232  global fdict
1233  global flist
1234  global f77symbol
1235  global doOpaqueXlate
1236  global arch
1237  global doWeakSymbols
1238  global useSetJmp
1239 
1240  opts, pargs = getopt.getopt(sys.argv[1:], '', ['f77symbol=', 'xlate', 'arch=', 'weak', 'usesetjmp'])
1241 
1242  print "MPI Wrapper Generator ($Revision: 442 $)"
1243  #print "opts=",opts
1244  #print "pargs=",pargs
1245 
1246  f77symbol = 'symbol'
1247  doOpaqueXlate = False
1248  doWeakSymbols = False
1249  useSetJmp = False
1250  arch = 'unknown'
1251 
1252  for o, a in opts:
1253  print "o: ",o," a: ",a
1254  if o == '--f77symbol':
1255  f77symbol = a
1256  if o == '--xlate':
1257  doOpaqueXlate = True
1258  if o == '--weak':
1259  doWeakSymbols = True
1260  if o == '--arch':
1261  arch = a
1262  if o == '--usesetjmp':
1263  useSetJmp = True
1264 
1265 
1266 
1267  if len(pargs) < 1:
1268  f = sys.__stdin__
1269  else:
1270  f = open(pargs[0])
1271  ReadInputFile(f)
1272 
1273  print "-----*----- Beginning parameter optimization"
1274  #ParameterOptimization()
1275 
1276  #GenerateStructureFile()
1279  if doWeakSymbols == True :
1281  GenerateLookup()
1282 
1283 
1284 
1287 main()
1288 
1289 #
1290 #
1291 # <license>
1292 #
1293 # Copyright (c) 2006, The Regents of the University of California.
1294 # Produced at the Lawrence Livermore National Laboratory
1295 # Written by Jeffery Vetter and Christopher Chambreau.
1296 # UCRL-CODE-223450.
1297 # All rights reserved.
1298 #
1299 # This file is part of mpiP. For details, see http://mpip.sourceforge.net/.
1300 #
1301 # Redistribution and use in source and binary forms, with or without
1302 # modification, are permitted provided that the following conditions are
1303 # met:
1304 #
1305 # * Redistributions of source code must retain the above copyright
1306 # notice, this list of conditions and the disclaimer below.
1307 #
1308 # * Redistributions in binary form must reproduce the above copyright
1309 # notice, this list of conditions and the disclaimer (as noted below) in
1310 # the documentation and/or other materials provided with the
1311 # distribution.
1312 #
1313 # * Neither the name of the UC/LLNL nor the names of its contributors
1314 # may be used to endorse or promote products derived from this software
1315 # without specific prior written permission.
1316 #
1317 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1318 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1319 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1320 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OF
1321 # THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY OR
1322 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
1323 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
1324 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
1325 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
1326 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
1327 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
1328 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1329 #
1330 #
1331 # Additional BSD Notice
1332 #
1333 # 1. This notice is required to be provided under our contract with the
1334 # U.S. Department of Energy (DOE). This work was produced at the
1335 # University of California, Lawrence Livermore National Laboratory under
1336 # Contract No. W-7405-ENG-48 with the DOE.
1337 #
1338 # 2. Neither the United States Government nor the University of
1339 # California nor any of their employees, makes any warranty, express or
1340 # implied, or assumes any liability or responsibility for the accuracy,
1341 # completeness, or usefulness of any information, apparatus, product, or
1342 # process disclosed, or represents that its use would not infringe
1343 # privately-owned rights.
1344 #
1345 # 3. Also, reference herein to any specific commercial products,
1346 # process, or services by trade name, trademark, manufacturer or
1347 # otherwise does not necessarily constitute or imply its endorsement,
1348 # recommendation, or favoring by the United States Government or the
1349 # University of California. The views and opinions of authors expressed
1350 # herein do not necessarily state or reflect those of the United States
1351 # Government or the University of California, and shall not be used for
1352 # advertising or product endorsement purposes.
1353 #
1354 # </license>
1355 #
1356 #
1357 # --- EOF
def CreateWrapper(funct, olist)
Create a MPI wrapper for one function using the information in the function dict. ...
def __init__(self, name, id, returntype, paramList, paramStr, protoline)
def GenerateStructureFile()
Create the structure files.
def GenerateSymbolDefs()
def ProcessWrapperPreLine(lastFunction, line)
def StandardFileHeader(fname)
create a standard file header and return the init list
def __init__(self, name, basetype, pointerLevel, arrayLevel)
def ProcessWrapperPostLine(lastFunction, line)
def ProcessDirectiveLine(lastFunction, line)
def GenerateLookup()
Generate a lookup table where mpiP can grab variables and function pointers.
def GenerateWeakSymbols()
def GenerateWrappers()
def ParamDictUpdate(fname)
ParamDictUpdate - updates the datastructures for a function after the basics have been entered...
def ReadInputFile(f)
Parses the input file and loads the information into the function dict.
def GetFortranSymbol(fsymtp, fsym)
def SpecialParamRecord(funct, param)
Some MPI types we want to record.
def ParameterOptimization()
Scan the lists of all functions and look for optimization opportunities (in space/speed).
def __init__(self, mpiType, varName)