Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load fftw library on macos if conda or homebrew used #1262

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ jobs:
- name: build help
run: |
cmake --build . -- buildhelp
- name: minimal tests
run: |
export OMP_NUM_THREADS=1
cmake --build . -- tests_minimal
- name: package
run: cmake --build . -- package
- name: Install
Expand Down Expand Up @@ -152,10 +148,6 @@ jobs:
- name: build help
run: |
cmake --build . -- buildhelp
- name: minimal tests
run: |
export OMP_NUM_THREADS=1
cmake --build . -- tests_minimal
- name: package
run: cmake --build . -- package
- name: Install
Expand Down Expand Up @@ -240,10 +232,6 @@ jobs:
- name: build help
run: |
cmake --build . -- buildhelp
- name: minimal tests
run: |
export OMP_NUM_THREADS=1
cmake --build . -- tests_minimal
- name: package
run: cmake --build . -- package
- name: Install
Expand Down Expand Up @@ -845,11 +833,6 @@ jobs:
run: |
%GITHUB_WORKSPACE%/bin/win32/nelson-cli --noipc --quiet -f %GITHUB_WORKSPACE%/tools/buildhelp/buildhelp.m

- name: Minimal tests
run: |
set NELSON_TERM_IS_UNICODE_SUPPORTED=TRUE
%GITHUB_WORKSPACE%/bin/win32/nelson-cli --noipc --quiet -f %GITHUB_WORKSPACE%/tools/tests_minimal/runtests_minimal.m

- name: Inno setup
run: |
%GITHUB_WORKSPACE%/bin/win32/nelson-cli --noipc --quiet -e run('%GITHUB_WORKSPACE%/tools/innosetup/innosetup.m');exit"
Expand Down
3 changes: 3 additions & 0 deletions bin/macOS/nelson
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ SCRIPT_DIRECTORY=$(cd "$(dirname "$0")"; pwd)
#==============================================================================
export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
#==============================================================================
# remove warning about deprecated functions on macOS Sequoia with Qt
export CFLOG_FORCE_DISABLE_STDERR=1
#==============================================================================
if test -d $SCRIPT_DIRECTORY/../lib/Nelson; then
CURRENT_DIRECTORY=$(pwd -P)
cd "$SCRIPT_DIRECTORY/../lib/Nelson"
Expand Down
76 changes: 54 additions & 22 deletions modules/fftw/src/cpp/FFTWWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#if WITH_OPENMP
#include <omp.h>
#endif
#include <cstdlib>
#include <algorithm>
#include "FFTWDynamicLibrary.hpp"
#include "FFTWWrapper.hpp"
#include "DynamicLibrary.hpp"
Expand Down Expand Up @@ -192,41 +194,71 @@ freeFFTWLibrary()
return false;
}
//=============================================================================
#if defined(__APPLE__)
static bool
loadFFTWLibraryOnMacOs()
{
// Lambda to attempt loading FFTW libraries from a given prefix
auto tryLoadLibrary = [](const char* prefix) -> bool {
if (prefix) {
std::string libPath = std::string(prefix) + "/lib/";
std::string fftwLibraryName = libPath + "libfftw3.3" + get_dynamic_library_extension();
std::string fftwfLibraryName = libPath + "libfftw3f" + get_dynamic_library_extension();
return loadFFTWLibrary(
utf8_to_wstring(fftwLibraryName), utf8_to_wstring(fftwfLibraryName));
}
return false;
};

// Try loading from CONDA_PREFIX first, then HOMEBREW_PREFIX if necessary
return tryLoadLibrary(std::getenv("CONDA_PREFIX"))
|| tryLoadLibrary(std::getenv("HOMEBREW_PREFIX"));
}
#endif
//=============================================================================
bool
loadFFTWLibrary()
{
if (fftwLoaded) {
return true;
}
bool res = false;
#ifdef _MSC_VER
std::wstring fftwLibraryName = L"libfftw3-3.dll";
std::wstring fftwfLibraryName = L"libfftw3f-3.dll";
res = loadFFTWLibrary(fftwLibraryName, fftwfLibraryName);
#else
std::string fftwLibraryName = "libfftw3" + get_dynamic_library_extension();
std::string fftwfLibraryName = "libfftw3f" + get_dynamic_library_extension();
res = loadFFTWLibrary(utf8_to_wstring(fftwLibraryName), utf8_to_wstring(fftwfLibraryName));
if (!res) {
std::string fftwLibraryName = "libfftw3" + get_dynamic_library_extension() + ".3";
std::string fftwfLibraryName = "libfftw3f" + get_dynamic_library_extension() + ".3";
res = loadFFTWLibrary(utf8_to_wstring(fftwLibraryName), utf8_to_wstring(fftwfLibraryName));
}
if (!res) {
// try with version 3.3 macos specific
std::string fftwLibraryName = "libfftw3.3" + get_dynamic_library_extension();
std::string fftwfLibraryName = "libfftw3f" + get_dynamic_library_extension() + ".3";
res = loadFFTWLibrary(utf8_to_wstring(fftwLibraryName), utf8_to_wstring(fftwfLibraryName));
}

#endif
if (res) {
auto getLibraryNames = []() -> std::vector<std::pair<std::string, std::string>> {
std::string ext = get_dynamic_library_extension();
return { { "libfftw3-3" + ext, "libfftw3f-3" + ext },
{ "libfftw3" + ext, "libfftw3f" + ext },
{ "libfftw3" + ext + ".3", "libfftw3f" + ext + ".3" },
{ "libfftw3.3" + ext, "libfftw3f" + ext } };
};

auto tryLoadLibrary = [](const auto& names) {
return loadFFTWLibrary(utf8_to_wstring(names.first), utf8_to_wstring(names.second));
};

auto initializeFffwThreads = []() {
#if WITH_OPENMP
if (fftw_init_threadsPtr && fftw_plan_with_nthreadsPtr) {
fftw_init_threadsPtr();
fftw_plan_with_nthreadsPtr(omp_get_max_threads());
}
#endif
};

bool res = false;
for (auto names : getLibraryNames()) {
res = tryLoadLibrary(names);
if (res) {
break;
}
}

#if defined(__APPLE__)
if (!res) {
res = loadFFTWLibraryOnMacOs();
}
#endif
if (res) {
initializeFffwThreads();
}
return res;
}
Expand Down
24 changes: 24 additions & 0 deletions modules/integer/tests/test_times_1.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%=============================================================================
% Copyright (c) 2016-present Allan CORNET (Nelson)
%=============================================================================
% This file is part of the Nelson.
%=============================================================================
% LICENCE_BLOCK_BEGIN
% SPDX-License-Identifier: LGPL-3.0-or-later
% LICENCE_BLOCK_END
%=============================================================================
R = intmax('int8') .* 2;
R = intmax('int8') .* -2;
%=============================================================================
R = intmax('int8') .* intmax('int8');
REF = intmax('int8');
assert_isequal(R, REF);
%=============================================================================
R = intmax('int8') .* intmin('int8');
REF = intmin('int8');
assert_isequal(R, REF);
%=============================================================================
R = intmin('int8') .* intmax('int8');
REF = intmin('int8');
assert_isequal(R, REF);
%=============================================================================
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@
% SPDX-License-Identifier: LGPL-3.0-or-later
% LICENCE_BLOCK_END
%=============================================================================
R = intmax('int8') .* 2;
R = intmax('int8') .* -2;
%=============================================================================
R = intmax('int8') .* intmax('int8');
REF = intmax('int8');
assert_isequal(R, REF);
%=============================================================================
R = intmax('int8') .* intmin('int8');
REF = intmin('int8');
assert_isequal(R, REF);
%=============================================================================
R = intmin('int8') .* intmax('int8');
REF = intmin('int8');
assert_isequal(R, REF);
%=============================================================================
R = intmin('int8') .* intmin('int8');
REF = intmax('int8');
assert_isequal(R, REF);
Expand Down
22 changes: 13 additions & 9 deletions modules/mex/tests/test_mxDuplicateArray_cell.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
end
%=============================================================================
if exist('mxDuplicateArray') == 0
test_dir = [tempdir(), 'mxDuplicateArray_cell'];
if isdir(test_dir)
rmdir(test_dir,'s');
try
test_dir = [tempdir(), 'mxDuplicateArray_cell'];
if isdir(test_dir)
rmdir(test_dir,'s');
end
mkdir(test_dir);
status = copyfile('mxDuplicateArray.c', test_dir);
assert_istrue(status);
cd(test_dir);
mex('mxDuplicateArray.c');
addpath(pwd())
catch NE
rethrow(NE);
end
mkdir(test_dir);
status = copyfile('mxDuplicateArray.c', test_dir);
assert_istrue(status);
cd(test_dir);
mex('mxDuplicateArray.c');
addpath(pwd())
end
%=============================================================================
REF = {1, single(2); 'Nelson Text in a cell', false};
Expand Down
Loading