multithreading demonstrated to work, but not safe yet

This commit is contained in:
Martin Reinecke 2020-01-03 18:26:53 +01:00
parent 0f8051fc28
commit 54cbae0534
3 changed files with 65 additions and 64 deletions

View file

@ -24,7 +24,7 @@ libsharp2_la_SOURCES = \
# any backward-compatible change: increase age
# any backward-incompatible change: age=0
# ==> age <= current
libsharp2_la_LDFLAGS = -version-info 0:0:0
libsharp2_la_LDFLAGS = -version-info 0:0:0 -lpthread
AM_CXXFLAGS = @AM_CXXFLAGS@

View file

@ -33,6 +33,7 @@
#include "libsharp2/sharp_utils.h"
#include "libsharp2/sharp_almhelpers.h"
#include "libsharp2/sharp_geomhelpers.h"
#include "mr_util/threading.h"
typedef complex<double> dcmplx;
typedef complex<float> fcmplx;
@ -760,14 +761,14 @@ NOINLINE static void map2phase (sharp_job *job, int mmax, int llim, int ulim)
}
else
{
#pragma omp parallel
mr::execDynamic(ulim-llim, 0, 1, [&](mr::Scheduler &sched)
{
ringhelper helper;
ringhelper_init(&helper);
int rstride=job->ginfo->nphmax+2;
double *ringtmp=RALLOC(double,job->nmaps*rstride);
#pragma omp for schedule(dynamic,1)
for (int ith=llim; ith<ulim; ++ith)
while (auto rng=sched.getNext()) for(auto ith=rng.lo+llim; ith<rng.hi+llim; ++ith)
{
int dim2 = job->s_th*(ith-llim);
ring2ringtmp(job,&(job->ginfo->pair[ith].r1),ringtmp,rstride);
@ -784,7 +785,7 @@ NOINLINE static void map2phase (sharp_job *job, int mmax, int llim, int ulim)
}
DEALLOC(ringtmp);
ringhelper_destroy(&helper);
} /* end of parallel region */
}); /* end of parallel region */
}
}
@ -805,14 +806,14 @@ NOINLINE static void phase2map (sharp_job *job, int mmax, int llim, int ulim)
}
else
{
#pragma omp parallel
mr::execDynamic(ulim-llim, 0, 1, [&](mr::Scheduler &sched)
{
ringhelper helper;
ringhelper_init(&helper);
int rstride=job->ginfo->nphmax+2;
double *ringtmp=RALLOC(double,job->nmaps*rstride);
#pragma omp for schedule(dynamic,1)
for (int ith=llim; ith<ulim; ++ith)
while (auto rng=sched.getNext()) for(auto ith=rng.lo+llim; ith<rng.hi+llim; ++ith)
{
int dim2 = job->s_th*(ith-llim);
for (int i=0; i<job->nmaps; ++i)
@ -829,7 +830,7 @@ NOINLINE static void phase2map (sharp_job *job, int mmax, int llim, int ulim)
}
DEALLOC(ringtmp);
ringhelper_destroy(&helper);
} /* end of parallel region */
}); /* end of parallel region */
}
}
@ -871,7 +872,7 @@ NOINLINE static void sharp_execute_job (sharp_job *job)
/* map->phase where necessary */
map2phase (job, mmax, llim, ulim);
#pragma omp parallel
mr::execDynamic(job->ainfo->nm, 0, 1, [&](mr::Scheduler &sched)
{
sharp_job ljob = *job;
ljob.opcnt=0;
@ -879,8 +880,7 @@ NOINLINE static void sharp_execute_job (sharp_job *job)
sharp_Ylmgen_init (&generator,lmax,mmax,ljob.spin);
alloc_almtmp(&ljob,lmax);
#pragma omp for schedule(dynamic,1)
for (int mi=0; mi<job->ainfo->nm; ++mi)
while (auto rng=sched.getNext()) for(auto mi=rng.lo; mi<rng.hi; ++mi)
{
/* alm->alm_tmp where necessary */
alm2almtmp (&ljob, lmax, mi);
@ -894,9 +894,10 @@ NOINLINE static void sharp_execute_job (sharp_job *job)
sharp_Ylmgen_destroy(&generator);
dealloc_almtmp(&ljob);
#pragma omp critical
//#pragma omp critical
//FIXME!!!!
job->opcnt+=ljob.opcnt;
} /* end of parallel region */
}); /* end of parallel region */
/* phase->map where necessary */
phase2map (job, mmax, llim, ulim);

View file

@ -36,10 +36,10 @@ using std::complex;
#include <experimental/simd>
using std::experimental::native_simd;
using std::experimental::reduce;
static constexpr size_t VLEN=native_simd<double>::size();
using Tv=native_simd<double>;
using Tm=Tv::mask_type;
typedef double Ts;
using Ts=Tv::value_type;
static constexpr size_t VLEN=Tv::size();
#define vload(a) (a)
#define vzero 0.