Skip to content

atomic for tasks #33

Description

@pojeda

Hi,

I wonder if there is support for atomic operations, especially in the context of tasks? I have extended a 2d integration from
one of our courses (https://uppmax.github.io/HPC-python/day4/parallel.html) using PyOMP:

importmathfromtimeimportperf_counterfromnumba.openmpimportnjitfromnumba.openmpimportopenmp_contextasopenmp# grid sizen=100000# Task granularity - number of iterations per taskTASK_SIZE=1000@njitdefintegration2d_omp(n):
h=math.pi/float(n)
total_sum=0.0withopenmp("parallel"):
withopenmp("single"):
# Create tasks for chunks of the outer loopnum_tasks= (n+TASK_SIZE-1) //TASK_SIZEfortask_idinrange(num_tasks):
withopenmp("task"):
i_start=task_id*TASK_SIZEi_end=min(i_start+TASK_SIZE, n)
local_sum=0.0foriinrange(i_start, i_end):
x=h* (i+0.5)
forjinrange(n):
y=h* (j+0.5)
local_sum+=math.sin(x+y)
# Atomic update of the shared sumwithopenmp("atomic"):
total_sum+=local_sum# Wait for all tasks to completewithopenmp("taskwait"):
passreturnh**2*total_sumif__name__=="__main__":
start=perf_counter()
integral=integration2d_omp(n)
end=perf_counter()
print(f"Integral value is {integral:e}, Error is {abs(integral-0.0):e}")
print(f"Time spent: {end-start:.2f} sec")

However, the atomic seems not to be supported yet. Do you have any suggestions for using tasks for this problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions