Skip to content

Commit

Permalink
Merge pull request #42 from Stoops-ML/0.3.2
Browse files Browse the repository at this point in the history
FIX: OMP parallelised loops + add tests
  • Loading branch information
Stoops-ML authored Oct 10, 2024
2 parents 7d3d440 + 22b87b5 commit f3afbaf
Show file tree
Hide file tree
Showing 19 changed files with 416 additions and 125 deletions.
12 changes: 6 additions & 6 deletions include/distances.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ void HaversineDouble(const double* rrmStart,
double mRadiusSphere,
double* mDistance)
{
int iPoint, iPointEnd, iPointStart;
int iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
iPointEnd = iPoint * NCOORDSINPOINT;
iPointStart = iPointEnd * isArraysSizeEqual;
int iPointEnd = iPoint * NCOORDSINPOINT;
int iPointStart = iPointEnd * isArraysSizeEqual;
mDistance[iPoint] = 2.0 * mRadiusSphere * asin(sqrt((1.0 - cos(rrmEnd[iPointEnd] - rrmStart[iPointStart]) + cos(rrmStart[iPointStart]) * cos(rrmEnd[iPointEnd]) * (1.0 - cos(rrmEnd[iPointEnd + 1] - rrmStart[iPointStart + 1]))) / 2.0));
}
}
Expand All @@ -53,11 +53,11 @@ void HaversineFloat(const float* rrmStart,
float mRadiusSphere,
float* mDistance)
{
int iPoint, iPointEnd, iPointStart;
int iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
iPointEnd = iPoint * NCOORDSINPOINT;
iPointStart = iPointEnd * isArraysSizeEqual;
int iPointEnd = iPoint * NCOORDSINPOINT;
int iPointStart = iPointEnd * isArraysSizeEqual;
mDistance[iPoint] = (float)(2.0) * mRadiusSphere * asinf(sqrtf(((float)(1.0) - cosf(rrmEnd[iPointEnd] - rrmStart[iPointStart]) + cosf(rrmStart[iPointStart]) * cosf(rrmEnd[iPointEnd]) * ((float)(1.0) - cosf(rrmEnd[iPointEnd + 1] - rrmStart[iPointStart + 1]))) / (float)(2.0)));
}
}
Expand Down
20 changes: 12 additions & 8 deletions include/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ void XXM2YYMDouble(const double* rrmPoint,
const double transform,
double* ddmPoint)
{
int iPoint, i;
int iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
i = iPoint * NCOORDSINPOINT;
int i = iPoint * NCOORDSINPOINT;
ddmPoint[i + 0] = rrmPoint[i + 0] * transform;
ddmPoint[i + 1] = rrmPoint[i + 1] * transform;
ddmPoint[i + 2] = rrmPoint[i + 2];
Expand All @@ -148,10 +148,10 @@ void XXM2YYMFloat(const float* rrmPoint,
const float transform,
float* ddmPoint)
{
int iPoint, i;
int iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
i = iPoint * NCOORDSINPOINT;
int i = iPoint * NCOORDSINPOINT;
ddmPoint[i + 0] = rrmPoint[i + 0] * transform;
ddmPoint[i + 1] = rrmPoint[i + 1] * transform;
ddmPoint[i + 2] = rrmPoint[i + 2];
Expand All @@ -167,8 +167,9 @@ void WrapsFloat3(const float* val,
int nPoints,
float* boundedVal)
{
int iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (int iPoint = 0; iPoint < nPoints; ++iPoint) {
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
boundedVal[iPoint] = fmodf(val[iPoint] - minVal[iPoint], maxVal[iPoint] - minVal[iPoint]) + minVal[iPoint];
if (boundedVal[iPoint] < minVal[iPoint])
boundedVal[iPoint] += maxVal[iPoint] - minVal[iPoint];
Expand All @@ -184,8 +185,9 @@ void WrapsDouble3(const double* val,
int nPoints,
double* boundedVal)
{
int iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (int iPoint = 0; iPoint < nPoints; ++iPoint) {
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
boundedVal[iPoint] = fmod(val[iPoint] - minVal[iPoint], maxVal[iPoint] - minVal[iPoint]) + minVal[iPoint];
if (boundedVal[iPoint] < minVal[iPoint])
boundedVal[iPoint] += maxVal[iPoint] - minVal[iPoint];
Expand All @@ -201,8 +203,9 @@ void WrapsFloat1(const float* val,
int nPoints,
float* boundedVal)
{
int iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (int iPoint = 0; iPoint < nPoints; ++iPoint) {
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
boundedVal[iPoint] = fmodf(val[iPoint] - minVal, maxVal - minVal) + minVal;
if (boundedVal[iPoint] < minVal)
boundedVal[iPoint] += maxVal - minVal;
Expand All @@ -218,8 +221,9 @@ void WrapsDouble1(const double* val,
int nPoints,
double* boundedVal)
{
int iPoint;
#pragma omp parallel for if (nPoints > omp_get_num_procs() * THREADING_CORES_MULTIPLIER)
for (int iPoint = 0; iPoint < nPoints; ++iPoint) {
for (iPoint = 0; iPoint < nPoints; ++iPoint) {
boundedVal[iPoint] = fmod(val[iPoint] - minVal, maxVal - minVal) + minVal;
if (boundedVal[iPoint] < minVal)
boundedVal[iPoint] += maxVal - minVal;
Expand Down
Loading

0 comments on commit f3afbaf

Please sign in to comment.