def _block0(): # omp for for i in omp.prange(8): time.sleep(random.randrange(3)) print str(omp.get_thread_num()) + ' thread\n', omp.barrier() print "done"
def _block0(): print str(omp.get_thread_num()) + ' a\n', time.sleep(random.randrange(3)) print str(omp.get_thread_num()) + ' b\n', time.sleep(random.randrange(3)) # omp barrier omp.barrier() print str(omp.get_thread_num()) + ' c\n',
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(): # omp for for n in omp.prange(_dict2['N'] * _dict2['N']): i = n / _dict2['N'] j = n % _dict2['N'] tmp = 0 for k in range(_dict2['N']): tmp = tmp + _dict2['a'][i * _dict2['N'] + k] * _dict2['b'][k * _dict2['N'] + j] _dict2['res'][n] = tmp 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 _block0(): # omp sections for OMP_SECTIONS_ID in omp.prange(2): # omp section if OMP_SECTIONS_ID == 0: print 'section 0 from ' + str(omp.get_thread_num()) + '\n', # omp section end # omp section if OMP_SECTIONS_ID == 1: print 'section 1 from ' + str(omp.get_thread_num()) + '\n', # omp section end # omp sections end omp.barrier()
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