def _block0():
     # omp for nowait
     for i in omp.prange(num_step):
         x = (i + 0.5) * step
         # omp critical
         omp.set_internal_lock(1)
         _dict1['ans'] += 4.0 / (1.0 + x * x)
         omp.unset_internal_lock(1)
Exemple #2
0
 def _block3():
     # omp for
     for i in omp.prange(num_step):
         x = (i + 0.5) * step
         # omp critical
         omp.set_internal_lock(2)
         _dict4['ans'] += 4.0 / (1.0 + x * x)
         omp.unset_internal_lock(2)
     omp.barrier()
 def _block0():
     # omp for reduction(+:ans)
     OMP_REDUCTION_VAR_0 = omp.reduction_init('+')
     for i in omp.prange(num_step):
         x = (i + 0.5) * step
         OMP_REDUCTION_VAR_0 += 4.0 / (1.0 + x * x)
     omp.set_internal_lock(0)
     _dict1['ans'] = omp.reduction('+', _dict1['ans'], OMP_REDUCTION_VAR_0)
     omp.unset_internal_lock(0)
     omp.barrier()
 def _block0():
     if omp.get_thread_num() == 0:
         print 'num_threads =', omp.get_num_threads()
     #omp for reduction(+:s)
     OMP_REDUCTION_VAR_0_0 = omp.reduction_init('+')
     for i in omp.prange(_dict1['n']):
         OMP_REDUCTION_VAR_0_0 += i
     omp.set_internal_lock(0)
     _dict1['s'] = omp.reduction('+', _dict1['s'], OMP_REDUCTION_VAR_0_0)
     omp.unset_internal_lock(0)
     omp.barrier()
def calc_pi_critical():
    ans = 0
    lock = omp.init_lock()
    #omp parallel num_threads(8) private(i,x)
    for i in omp.prange(num_step):
        x = (i+0.5)*step
        omp.set_internal_lock(1)
        ans += 4.0/(1.0 + x*x)
        omp.unset_internal_lock(1)
    #omp parallel end
    print ans * step
def calc_pi_for():
    ans = 0
    lock = omp.init_lock()
    tmp_ans = omp.reduction_init('+')
    #omp parallel num_threads(8) private(i,x)
    for i in omp.prange(num_step):
        x = (i+0.5)*step
        ans += 4.0/(1.0 + x*x)
    omp.set_internal_lock(0)
    tmp_ans = omp.reduction('+', tmp_ans, ans)
    omp.unset_internal_lock(0)
    omp.barrier()
    ans = tmp_ans
    #omp parallel end
    print ans * step