rainwoodman / sharedmem

A different flavor of multiprocessing in Python
GNU General Public License v3.0
81 stars 9 forks source link

Thinking about OpenMP. #3

Open rainwoodman opened 9 years ago

rainwoodman commented 9 years ago

The old openmp-like support was dropped in the single-file rewrite. Time to think about this more carefully.

@omp.parallel(private=['a', 'b'], shared=['b'], reduce=[operator.add, 'c'])
def parallel_section(a, b, c):
    if omp.master:
        b[...] = 0
        c[...] = 0
    omp.barrier()
    for i in omp.range(0, 1000, schedule='static'):
        c[...] += i
        a[...] += i
        with omp.critical:
             b[...] += i

a = numpy.empty((,), dtype='i8')
b = numpy.empty((,), dtype='i8')
c = numpy.empty((,), dtype='i8')

parallel_section(1, b, c)

assert c == (0 + 999)*1000 / 2
assert b == (0 + 999)*1000 / 2
rainwoodman commented 8 years ago

We need a way to ensure MapReduce dispatches exactly one payload per process. An ordered at the begining of the work function should be able to achieve this.