-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhdf5_converter.rg
126 lines (101 loc) · 4.2 KB
/
hdf5_converter.rg
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
import "regent"
require("barnes_hut_common")
local c = regentlib.c
local cstring = terralib.includec("string.h")
local std = terralib.includec("stdlib.h")
local hdf5 = terralib.includec(os.getenv("HDF_HEADER") or "hdf5.h")
hdf5.H5F_ACC_TRUNC = 2
hdf5.H5T_STD_I32LE = hdf5.H5T_STD_I32LE_g
hdf5.H5T_IEEE_F64LE = hdf5.H5T_IEEE_F64LE_g
hdf5.H5P_DEFAULT = 0
struct Config {
input_file : rawstring,
input_file_set : bool,
output_file : rawstring,
output_file_set : bool,
num_bodies : uint,
}
terra parse_input_args()
var conf : Config
conf.input_file_set = false
conf.output_file_set = false
conf.num_bodies = -1
var args = c.legion_runtime_get_input_args()
for i = 0, args.argc do
if cstring.strcmp(args.argv[i], "-i") == 0 then
i = i + 1
conf.input_file = args.argv[i]
conf.input_file_set = true
elseif cstring.strcmp(args.argv[i], "-o") == 0 then
i = i + 1
conf.output_file = args.argv[i]
conf.output_file_set = true
elseif cstring.strcmp(args.argv[i], "-n") == 0 then
i = i + 1
conf.num_bodies = std.atoi(args.argv[i])
end
end
return conf
end
terra generate_hdf5_file(filename : rawstring, num_bodies: uint)
var fid = hdf5.H5Fcreate(filename, hdf5.H5F_ACC_TRUNC, hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT)
var h_dims : hdf5.hsize_t[1]
h_dims[0] = num_bodies
var did = hdf5.H5Screate_simple(1, h_dims, [&uint64](0))
var ds1id = hdf5.H5Dcreate2(fid, "index", hdf5.H5T_STD_I32LE, did,
hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT)
hdf5.H5Dclose(ds1id)
var ds2id = hdf5.H5Dcreate2(fid, "mass_x", hdf5.H5T_IEEE_F64LE, did,
hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT)
hdf5.H5Dclose(ds2id)
var ds3id = hdf5.H5Dcreate2(fid, "mass_y", hdf5.H5T_IEEE_F64LE, did,
hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT)
hdf5.H5Dclose(ds3id)
var ds4id = hdf5.H5Dcreate2(fid, "speed_x", hdf5.H5T_IEEE_F64LE, did,
hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT)
hdf5.H5Dclose(ds4id)
var ds5id = hdf5.H5Dcreate2(fid, "speed_y", hdf5.H5T_IEEE_F64LE, did,
hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT)
hdf5.H5Dclose(ds5id)
var ds6id = hdf5.H5Dcreate2(fid, "mass", hdf5.H5T_IEEE_F64LE, did,
hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT, hdf5.H5P_DEFAULT)
hdf5.H5Dclose(ds6id)
hdf5.H5Sclose(did)
hdf5.H5Fclose(fid)
end
task main()
var conf = parse_input_args()
var input = region(ispace(ptr, conf.num_bodies), body)
var fp = c.fopen(conf.input_file, "r")
var line : int8[1024]
for i=0,conf.num_bodies do
c.fgets(line, 1024, fp)
var index = std.atoi(cstring.strtok(line, ","))
input[index].index = index
input[index].mass_x = std.atof(cstring.strtok([&int8](0), ","))
input[index].mass_y = std.atof(cstring.strtok([&int8](0), ","))
input[index].speed_x = std.atof(cstring.strtok([&int8](0), ","))
input[index].speed_y = std.atof(cstring.strtok([&int8](0), ","))
input[index].mass = std.atof(cstring.strtok([&int8](0), ","))
end
c.fclose(fp)
generate_hdf5_file(conf.output_file, conf.num_bodies)
var output = region(ispace(ptr, conf.num_bodies), body)
attach(hdf5, output.{mass, mass_x, mass_y, speed_x, speed_y, index}, conf.output_file, regentlib.file_read_write)
acquire(output.{mass, mass_x, mass_y, speed_x, speed_y, index})
copy(input.{mass, mass_x, mass_y, speed_x, speed_y, index}, output.{mass, mass_x, mass_y, speed_x, speed_y, index})
release(output.{mass, mass_x, mass_y, speed_x, speed_y, index})
detach(hdf5, output.{mass, mass_x, mass_y, speed_x, speed_y, index})
end
if os.getenv('SAVEOBJ') == '1' then
local root_dir = arg[0]:match(".*/") or "./"
local out_dir = (os.getenv('OBJNAME') and os.getenv('OBJNAME'):match('.*/')) or root_dir
local link_flags = terralib.newlist({"-L" .. out_dir, "-lm"})
if os.getenv('STANDALONE') == '1' then
os.execute('cp ' .. os.getenv('LG_RT_DIR') .. '/../bindings/regent/libregent.so ' .. out_dir)
end
local exe = os.getenv('OBJNAME') or "hdf5_converter"
regentlib.saveobj(main, exe, "executable", nil, link_flags)
else
regentlib.start(main)
end