-
Notifications
You must be signed in to change notification settings - Fork 180
Description
#define EIGEN_USE_BLAS
#define EIGEN_USE_LAPACKE_STRICT
#define EIGEN_VECTORIZE
#define TEST_DATA_SIZE 1000
#include <iostream>
#include <chrono>
#include <iomanip>
#include <thread>
#include <Eigen/Dense>
int main() {
// Configure Eigen for maximum performance
Eigen::setNbThreads(static_cast<int>(std::thread::hardware_concurrency()));
Eigen::initParallel();
constexpr int precision = 4;
// Generate random matrices a and b
const auto a = Eigen::MatrixXd::Random(TEST_DATA_SIZE, TEST_DATA_SIZE);
const auto b = Eigen::MatrixXd::Random(TEST_DATA_SIZE, TEST_DATA_SIZE);
std::cout << "Init matrix finished" << std::endl;
auto sqr_result = a.array().pow(2);
// Time the matrix multiplication
const auto start = std::chrono::high_resolution_clock::now();
const auto c = a * b; // Perform matrix multiplication
// Compute and display time taken
const auto elapsed = std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - start);
std::cout << "calculate time for all signals: " << elapsed.count() * 1000 * 1000 << " us.\n";
Eigen::IOFormat CleanFormat(precision, 0, ", ", "\n", "[", "]");
std::cout << static_cast<double>(c(0, 0)) << std::endl;
return 0;
}
Above is my test demo, when running it on win10 with Clion and the bundled mingGW(11.0 w64 and Cmake 3.29.6), get the suspected link error as "Process finished with exit code -1073741515 (0xC0000135)"
But If I comment the last second line "std::cout << static_cast(c(0, 0)) << std::endl;", every thing will be ok.
I will also provide you with my cmakelists
cmake_minimum_required(VERSION 3.29)
project(EigenTest)
set(CMAKE_CXX_STANDARD 17)
find_package(Boost REQUIRED)
find_package(OpenMP REQUIRED)
set(EIGEN3_DIR "${CMAKE_SOURCE_DIR}/eigen-3.4.0")
set(BLAS_DIR "${CMAKE_SOURCE_DIR}/libs/BLAS")
set(LAPACKE_DIR "${CMAKE_SOURCE_DIR}/libs/LAPACKE")
add_executable(EigenTest main.cpp)
target_include_directories(EigenTest PRIVATE ${EIGEN3_DIR})
target_link_directories(EigenTest PRIVATE "libs")
# Compiler-specific optimization flags
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
target_compile_options(EigenTest PRIVATE
-O3 # Maximum optimization
-march=native # Optimize for current CPU
-mtune=native
-fopenmp # OpenMP support
-ffast-math # Aggressive math optimizations
)
target_link_options(EigenTest PRIVATE
-fopenmp # Link OpenMP runtime
)
target_link_libraries(EigenTest PRIVATE "${BLAS_DIR}/libblas.dll" "${BLAS_DIR}/libblas.lib")
target_link_libraries(EigenTest PRIVATE "${LAPACKE_DIR}/liblapacke.dll" "${LAPACKE_DIR}/liblapacke.lib")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(EigenTest PRIVATE
-O3
-march=native
-mtune=native
-fopenmp
)
target_link_options(EigenTest PRIVATE
-fopenmp # Link OpenMP runtime
)
target_link_libraries(EigenTest PRIVATE "${BLAS_DIR}/libblas.dll" "${BLAS_DIR}/libblas.lib")
target_link_libraries(EigenTest PRIVATE "${LAPACKE_DIR}/liblapacke.dll" "${LAPACKE_DIR}/liblapacke.lib")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
target_compile_options(EigenTest PRIVATE
/O2 # Maximum optimization
/arch:AVX2 # Enable AVX2 instructions
/openmp # OpenMP support
)
endif()
Urgent need for a reply, so that can make me understand whether the reason was the wrong library file, the wrong cmake command, or some other problem.
BLAS and LAPACK libs are downloaded from LAPACK for Windows
I choose the first one:
Prebuilt dynamic libraries using Mingw
Requirement: Mingw 32 bits or 64 bits
Information: Those libraries were built with CMAKE for Visual Studio 2015 and Mingw compilers and correspond to LAPACK 3.7.0 + Bug Fix.
Thanks!