exaloop / codon

A high-performance, zero-overhead, extensible Python compiler using LLVM
https://docs.exaloop.io/codon
Other
13.96k stars 498 forks source link

Wish request: omp.for_break and omp.for_continue #443

Closed marioroy closed 10 months ago

marioroy commented 11 months ago

In writing the parallel t_is_prime demonstration, I find it awkward exiting the application from within the parallel for loop. Folks have suggested the continue statement for OpenMP using C/C++ which I tried. Doing so causes Codon to disable OpenMP somehow. Is that a bug?

@par(schedule='dynamic', chunk_size=1, ordered=True)
for chunk_id in range(num_chunks):
    if not_prime: continue

    low = uint(chunk_size) * uint(chunk_id) + uint(6) - uint(1)
    high = low + uint(chunk_size) - uint(1)
    if high > q: high = q

    if _DEBUG:
        show_chunk_info(chunk_id, low, high)

    while True:
        if low > high:
            break
        if n % low == uint(0) or n % (low + uint(2)) == uint(0):
            not_prime += 1
            break
        low += uint(6)

  # if not_prime:
  #     # OpenMP lacks omp.for_break/omp.for_continue capabilities.
  #     terminate_early(n)  # so, exit the application```

  # if not_prime: omp.for_break     # <-- feature request

I asked on stackoverflow where to submit a feature request for OpenMP.

As always, thank you for Codon.