puts "========="
puts "OCC25788"
puts "========="
puts ""
###############################################
# Parallelization of the BOP Builder algorithm on second level
###############################################

# box plate to cut the holes from
box b1 100 100 1

# N defines number of holes along each of X and Y, thus total N^2 holes
# will be drilled; note that the algorithm iself is likely to be quadratic
# for number of shapes, i.e. CPU 
set N 40
set holes {}
for {set i 1} {$i < $N} {incr i} {
 for {set j 1} {$j < $N} {incr j} {
   pcylinder p_${i}_$j 0.5 1
   ttranslate p_${i}_$j [expr $i * 100. / $N]  [expr $j * 100. / $N]  0.
   lappend holes p_${i}_$j
 }
}

eval compound $holes b2

bclearobjects
bcleartools
baddobjects b1
baddtools b2

brunparallel 1

dchrono cpu reset
dchrono cpu start
bcut r b1 b2 
dchrono cpu stop
set chrono_info [dchrono cpu show]

if { [regexp {Debug mode} [dversion]] } {
  if { [regexp {Windows} [dversion]] } {
    set max_time 200
  } else {
    set max_time 200
  }
} else {
  if { [regexp {Windows} [dversion]] } {
    set max_time 50
  } else {
    set max_time 50
  }
}

regexp {CPU user time: ([-0-9.+eE]+) seconds} ${chrono_info} full z
puts "$z"

if { $z > ${max_time} } {                                         
    puts "Elapsed time is more than ${max_time} seconds - Faulty"
} else {
    puts "Elapsed time is less than ${max_time} seconds - OK"
}
