16 |
|
my @savedARGV = @ARGV; |
17 |
|
my $tensortree = 0; |
18 |
|
my $ttlog2 = 4; |
19 |
< |
my $nsamp = 1000; |
19 |
> |
my $nsamp = 2000; |
20 |
|
my $rtargs = "-w -ab 5 -ad 700 -lw 3e-6"; |
21 |
|
my $mgfin = 0; |
22 |
|
my $geout = 1; |
23 |
|
my $nproc = 1; |
24 |
|
my $doforw = 0; |
25 |
|
my $doback = 1; |
26 |
+ |
my $gunit = "Meter"; |
27 |
|
my @dim; |
28 |
|
# Get options |
29 |
|
while ($#ARGV >= 0) { |
34 |
|
shift @ARGV; |
35 |
|
} elsif ("$ARGV[0]" =~ /^[-+]g/) { |
36 |
|
$geout = ("$ARGV[0]" =~ /^\+/); |
37 |
+ |
$gunit = $ARGV[1]; |
38 |
+ |
if ($gunit !~ /^(?i)(meter|foot|inch|centimeter|millimeter)$/) { |
39 |
+ |
die "Illegal geometry unit '$gunit': must be meter, foot, inch, centimeter, or millimeter\n"; |
40 |
+ |
} |
41 |
+ |
shift @ARGV; |
42 |
|
} elsif ("$ARGV[0]" =~ /^[-+]f/) { |
43 |
|
$doforw = ("$ARGV[0]" =~ /^\+/); |
44 |
|
} elsif ("$ARGV[0]" =~ /^[-+]b/) { |
115 |
|
<Name>Name</Name> |
116 |
|
<Manufacturer>Manufacturer</Manufacturer> |
117 |
|
'; |
118 |
< |
printf "\t\t<Thickness unit=\"Meter\">%.3f</Thickness>\n", $dim[5] - $dim[4]; |
119 |
< |
printf "\t\t<Width unit=\"Meter\">%.3f</Width>\n", $dim[1] - $dim[0]; |
120 |
< |
printf "\t\t<Height unit=\"Meter\">%.3f</Height>\n", $dim[3] - $dim[2]; |
118 |
> |
printf "\t\t<Thickness unit=\"$gunit\">%.3f</Thickness>\n", $dim[5] - $dim[4]; |
119 |
> |
printf "\t\t<Width unit=\"$gunit\">%.3f</Width>\n", $dim[1] - $dim[0]; |
120 |
> |
printf "\t\t<Height unit=\"$gunit\">%.3f</Height>\n", $dim[3] - $dim[2]; |
121 |
|
print "\t\t<DeviceType>Integral</DeviceType>\n"; |
122 |
|
# Output MGF description if requested |
123 |
|
if ( $geout ) { |
124 |
< |
print "\t\t<Geometry format=\"MGF\" unit=\"Meter\">\n"; |
124 |
> |
print "\t\t<Geometry format=\"MGF\" unit=\"$gunit\">\n"; |
125 |
|
printf "xf -t %.6f %.6f 0\n", -($dim[0]+$dim[1])/2, -($dim[2]+$dim[3])/2; |
126 |
|
open(MGFSCN, "< $mgfscn"); |
127 |
|
while (<MGFSCN>) { print $_; } |
149 |
|
</WindowElement> |
150 |
|
'; |
151 |
|
# Clean up temporary files and exit |
146 |
– |
if ( $persistfile && open(PFI, "< $persistfile") ) { |
147 |
– |
while (<PFI>) { |
148 |
– |
s/^[^ ]* //; |
149 |
– |
kill('ALRM', $_); |
150 |
– |
last; |
151 |
– |
} |
152 |
– |
close PFI; |
153 |
– |
} |
152 |
|
exec("rm -rf $td"); |
153 |
|
|
154 |
|
#-------------- End of main program segment --------------# |
155 |
|
|
156 |
+ |
#++++++++++++++ Kill persistent rtrace +++++++++++++++++++# |
157 |
+ |
sub persist_end { |
158 |
+ |
if ( $persistfile && open(PFI, "< $persistfile") ) { |
159 |
+ |
while (<PFI>) { |
160 |
+ |
s/^[^ ]* //; |
161 |
+ |
kill('ALRM', $_); |
162 |
+ |
last; |
163 |
+ |
} |
164 |
+ |
close PFI; |
165 |
+ |
} |
166 |
+ |
} |
167 |
+ |
|
168 |
|
#++++++++++++++ Tensor tree BSDF generation ++++++++++++++# |
169 |
|
sub do_tree_bsdf { |
170 |
|
# Get sampling rate and subdivide task |
171 |
|
my $ns2 = $ns; |
172 |
|
$ns2 /= 2 if ( $tensortree == 3 ); |
173 |
< |
@pdiv = (0, int($ns2/$nproc)); |
174 |
< |
my $nrem = $ns2 % $nproc; |
175 |
< |
for (my $i = 1; $i < $nproc; $i++) { |
173 |
> |
my $nsplice = $nproc; |
174 |
> |
$nsplice *= 10 if ($nproc > 1); |
175 |
> |
$nsplice = $ns2 if ($nsplice > $ns2); |
176 |
> |
$nsplice = 999 if ($nsplice > 999); |
177 |
> |
@pdiv = (0, int($ns2/$nsplice)); |
178 |
> |
my $nrem = $ns2 % $nsplice; |
179 |
> |
for (my $i = 1; $i < $nsplice; $i++) { |
180 |
|
my $nv = $pdiv[$i] + $pdiv[1]; |
181 |
|
++$nv if ( $nrem-- > 0 ); |
182 |
|
push @pdiv, $nv; |
225 |
|
print "\t\t<IncidentDataStructure>TensorTree$tensortree</IncidentDataStructure>\n"; |
226 |
|
print "\t</DataDefinition>\n"; |
227 |
|
# Fork parallel rtcontrib processes to compute each side |
228 |
+ |
my $npleft = $nproc; |
229 |
|
if ( $doback ) { |
230 |
< |
for (my $proc = 0; $proc < $nproc; $proc++) { |
231 |
< |
bg_tree_rtcontrib(0, $proc); |
230 |
> |
for (my $splice = 0; $splice < $nsplice; $splice++) { |
231 |
> |
if (! $npleft ) { |
232 |
> |
wait(); |
233 |
> |
die "rtcontrib process reported error" if ( $? ); |
234 |
> |
$npleft++; |
235 |
> |
} |
236 |
> |
bg_tree_rtcontrib(0, $splice); |
237 |
> |
$npleft--; |
238 |
|
} |
239 |
|
while (wait() >= 0) { |
240 |
|
die "rtcontrib process reported error" if ( $? ); |
241 |
+ |
$npleft++; |
242 |
|
} |
243 |
+ |
persist_end(); |
244 |
|
ttree_out(0); |
245 |
|
} |
246 |
|
if ( $doforw ) { |
247 |
< |
for (my $proc = 0; $proc < $nproc; $proc++) { |
248 |
< |
bg_tree_rtcontrib(1, $proc); |
247 |
> |
for (my $splice = 0; $splice < $nsplice; $splice++) { |
248 |
> |
if (! $npleft ) { |
249 |
> |
wait(); |
250 |
> |
die "rtcontrib process reported error" if ( $? ); |
251 |
> |
$npleft++; |
252 |
> |
} |
253 |
> |
bg_tree_rtcontrib(1, $splice); |
254 |
> |
$npleft--; |
255 |
|
} |
256 |
|
while (wait() >= 0) { |
257 |
|
die "rtcontrib process reported error" if ( $? ); |
258 |
+ |
$npleft++; |
259 |
|
} |
260 |
+ |
persist_end(); |
261 |
|
ttree_out(1); |
262 |
|
} |
263 |
|
} # end of sub do_tree_bsdf() |
264 |
|
|
265 |
< |
# Run i'th rtcontrib process for generating tensor tree samples |
265 |
> |
# Run rtcontrib process in background to generate tensor tree samples |
266 |
|
sub bg_tree_rtcontrib { |
267 |
|
my $pid = fork(); |
268 |
|
die "Cannot fork new process" unless defined $pid; |