Skip to content

Commit

Permalink
Fix OpenMP threshold code on Intel Macs (#4932)
Browse files Browse the repository at this point in the history
* Fix SIMD threshold code on Intel Macs

* Cleanup test_threshold.py
  • Loading branch information
titodalcanton authored Nov 12, 2024
1 parent 1ab428e commit f8c2f20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
11 changes: 7 additions & 4 deletions pycbc/events/simd_threshold_ccode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ void _parallel_threshold(int64_t N, std::complex<float> * __restrict arr,

#pragma omp ordered
{
t+=c;
t += c;
memmove(
outl + t - c, outl + start, sizeof(unsigned int)*c
);
memmove(
outv + t - c, outv + start, sizeof(std::complex<float>)*c
);
}
memmove(outl+t-c, outl+start, sizeof(unsigned int)*c);
memmove(outv+t-c, outv+start, sizeof(std::complex<float>)*c);

}

count[0] = t;
Expand Down
30 changes: 12 additions & 18 deletions test/test_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,41 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

#
# =============================================================================
#
# Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.waveform module
Unit tests for PyCBC's thresholding code.
"""

import unittest
import numpy
from pycbc.types import *
from pycbc.scheme import *
from pycbc.events import *
from pycbc.types import Array, complex64
from pycbc.events import threshold
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Threshold")

from pycbc.events.threshold_cpu import threshold_numpy
trusted_threshold = threshold_numpy
from pycbc.events.threshold_cpu import threshold_numpy as trusted_threshold


class TestThreshold(unittest.TestCase):
def setUp(self,*args):
def setUp(self, *args):
self.context = _context
self.scheme = _scheme
r = numpy.random.uniform(low=-1, high=1.0, size=2**20)
i = numpy.random.uniform(low=-1, high=1.0, size=2**20)
v = r + i*1.0j
v = r + i * 1.0j
self.series = Array(v, dtype=complex64)
self.threshold = 1.3
self.locs, self.vals = trusted_threshold(self.series, self.threshold)
self.tolerance = 1e-6
print(len(self.locs), len(self.vals))
print(f'Reference: {len(self.locs)} locs, {len(self.vals)} vals')

def test_threshold(self):
with self.context:
locs, vals = threshold(self.series, self.threshold)
print(f'Test: {len(locs)} locs, {len(vals)} vals')
self.assertTrue((locs == self.locs).all())
self.assertTrue((vals == self.vals).all())
print(len(locs), len(vals))


suite = unittest.TestSuite()
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestThreshold))

Expand Down

0 comments on commit f8c2f20

Please sign in to comment.