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

Remove UNI_OMP guards surrounding #pragma omp... #526

Merged
merged 4 commits into from
Dec 2, 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
61 changes: 14 additions & 47 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# set(CMAKE_CXX_EXTENSIONS OFF)
message(STATUS " Generator: ${CMAKE_GENERATOR}")
message(STATUS " Build Target: ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS " Installation Prefix: ${CMAKE_INSTALL_PREFIX}")
Expand Down Expand Up @@ -95,7 +94,8 @@ option(DEV_MODE "Build testing dev_test.cpp with cytnx" OFF)
# #####################################################################
project(CYTNX VERSION ${CYTNX_VERSION} LANGUAGES CXX C)

# C++ uses link-time optimization anyway; this enables additionally -flto=auto, for parallel compilation
# C++ uses link-time optimization anyway; this enables additionally -flto=auto,
# for parallel compilation
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)

add_library(cytnx STATIC)
Expand All @@ -117,20 +117,9 @@ target_include_directories(cytnx SYSTEM
${Boost_INCLUDE_DIRS}
)

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=0 -Wno-c++11-narrowing -w")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=0 -w -fsized-deallocation -fsanitize=address")

target_compile_options(cytnx PUBLIC -Wformat=0 -w -fsized-deallocation)

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=0 -w -fsized-deallocation -diag-disable=10441")

# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LIBCPP_DISABLE_AVAILABILITY")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION")
target_compile_features(cytnx PUBLIC cxx_std_17)

# target_compile_definitions(cytnx PUBLIC _LIBCPP_DISABLE_AVAILABILITY)
# target_compile_definitions(cytnx PUBLIC _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION)
# set_property(TARGET cytnx PROPERTY CXX_STANDARD 11)
add_subdirectory(src)

if(USE_DEBUG)
Expand All @@ -140,23 +129,14 @@ if(USE_DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
endif()

if(RUN_TESTS)
# Include CTest explicitly to suppress the error that DartConfiguration.tcl
# is not found
include(CTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
target_link_libraries(cytnx PUBLIC "-lgcov --coverage")
add_subdirectory(tests)
#add_subdirectory(bm_tests)
endif()

include(GNUInstallDirs)

if(USE_ICPC)
target_compile_definitions(cytnx PUBLIC UNI_ICPC)
# This option is to disable the warning of icpc
target_compile_options(cytnx PUBLIC -diag-disable=10441)
# This option is to maintain consistency of the floating point operation, also try to improve the performance
# This option is to maintain consistency of the floating point operation, also
# try to improve the performance
target_compile_options(cytnx PUBLIC -fp-model consistent -fimf-use-svml)
endif()

Expand Down Expand Up @@ -207,36 +187,24 @@ endif() # Backend torch
# ## Get Gtest & benchmark
# #####################################################################
if(RUN_TESTS)
find_package(GTest REQUIRED)
#find_package(benchmark REQUIRED)


#include(FetchContent)
#FetchContent_Declare(
# googletest
# URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
#)
# Include CTest explicitly to suppress the error that DartConfiguration.tcl
# is not found
include(CTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
target_link_libraries(cytnx PUBLIC "-lgcov --coverage")
# "-fopenmp" flag is appended to CMAKE_CXX_FLAGS in CytnxBKNDCMakeLists.cmake.
# To make the executalbe targets defined under tests/ link OpenMP correctly,
# tests/ must be added after including CytnxBKNDCMakeLists.cmake.
add_subdirectory(tests)
#add_subdirectory(bm_tests)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

#FetchContent_Declare(
# googlebenchmark
# GIT_REPOSITORY https://github.com/google/benchmark.git
# GIT_TAG v1.7.1) # need master for benchmark::benchmark
#set(BENCHMARK_ENABLE_TESTING off) # to suppress benchmark internal tests

#FetchContent_MakeAvailable(
# googletest
# googlebenchmark)
endif()

# #######
# ## Python wrapper
# #######
IF(BUILD_PYTHON)
# PythonInterp is removed in newer version of cmake
# find_package(PythonInterp REQUIRED)
find_package (Python COMPONENTS Interpreter Development)
find_package(pybind11 REQUIRED)

Expand Down Expand Up @@ -406,7 +374,6 @@ message(STATUS " CXX Flags: ${CMAKE_CXX_FLAGS}")
message(STATUS " BLAS and LAPACK Libraries: ${LAPACK_LIBRARIES}")
message(STATUS " Link libraries: ${CYTNX_LINK_Libs}")

# # this need to append into the linkflags.tmp
FILE(APPEND "${CMAKE_BINARY_DIR}/linkflags.tmp" "${LAPACK_LIBRARIES}\n" "")
FILE(APPEND "${CMAKE_BINARY_DIR}/cxxflags.tmp" "${CMAKE_CXX_FLAGS}\n" "")

Expand Down
4 changes: 0 additions & 4 deletions CytnxBKNDCMakeLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,6 @@ if(USE_OMP)
else()
message( STATUS " Build OMP Support: NO")

if(USE_MKL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif()

if(USE_HPTT)
find_package( OpenMP )
if ( OPENMP_FOUND )
Expand Down
6 changes: 2 additions & 4 deletions src/Accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,8 @@ namespace cytnx {
pos.clear();
pos.resize(this->idx_list.size());
len = pos.size();
// cout << "list in accessor len:" <<len << endl;
#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
// cout << "list in accessor len:" <<len << endl;
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 i = 0; i < this->idx_list.size(); i++) {
// checking:
if (this->idx_list[i] < 0) {
Expand Down
20 changes: 5 additions & 15 deletions src/Bond.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ namespace cytnx {
new_qnums = std::vector<std::vector<cytnx_int64>>(Dnew_qnums,
std::vector<cytnx_int64>(this->Nsym()));

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 d = 0; d < new_qnums.size(); d++) {
for (cytnx_uint32 i = 0; i < this->Nsym(); i++) {
if (bd_in->type() != this->type()) {
Expand Down Expand Up @@ -169,9 +167,7 @@ namespace cytnx {
new_qnums =
std::vector<std::vector<cytnx_int64>>(this->_dim, std::vector<cytnx_int64>(this->Nsym()));

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 d = 0; d < this->_dim; d++) {
for (cytnx_uint32 i = 0; i < this->Nsym(); i++) {
if (bd_in->type() != this->type()) {
Expand Down Expand Up @@ -252,9 +248,7 @@ namespace cytnx {
new_qnums = std::vector<std::vector<cytnx_int64>>(Dnew_qnums,
std::vector<cytnx_int64>(this->Nsym()));

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 d = 0; d < new_qnums.size(); d++) {
for (cytnx_uint32 i = 0; i < this->Nsym(); i++) {
this->_syms[i].combine_rule_(new_qnums[d][i],
Expand All @@ -276,9 +270,7 @@ namespace cytnx {
new_qnums =
std::vector<std::vector<cytnx_int64>>(this->_dim, std::vector<cytnx_int64>(this->Nsym()));

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 d = 0; d < this->_dim; d++) {
for (cytnx_uint32 i = 0; i < this->Nsym(); i++) {
this->_syms[i].combine_rule_(new_qnums[d][i],
Expand Down Expand Up @@ -470,9 +462,7 @@ namespace cytnx {
std::vector<std::vector<cytnx_int64>> Bond_impl::calc_reverse_qnums() {
std::vector<std::vector<cytnx_int64>> out(this->_qnums.size(),
std::vector<cytnx_int64>(this->_syms.size()));
#ifdef UNI_OMP
#pragma omp parallel for
#endif
#pragma omp parallel for
for (cytnx_uint64 i = 0; i < out.size(); i++) {
for (int j = 0; j < out[i].size(); j++) {
this->_syms[j].reverse_rule_(out[i][j], this->_qnums[i][j]);
Expand Down
17 changes: 5 additions & 12 deletions src/Device.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "Device.hpp"

#include <thread>

#include "cytnx_error.hpp"
#ifdef UNI_OMP
#include <omp.h>
Expand All @@ -7,7 +10,7 @@
using namespace std;
namespace cytnx {

Device_class::Device_class() : Ngpus(0), Ncpus(1) {
Device_class::Device_class() : Ngpus(0), Ncpus(std::thread::hardware_concurrency()) {
// cout << "init_device class!" << endl;
#ifdef UNI_GPU

Expand Down Expand Up @@ -38,17 +41,7 @@ namespace cytnx {
}
}
}

#endif

#ifdef UNI_OMP
#pragma omp parallel
{
if (omp_get_thread_num() == 0) {
Ncpus = omp_get_num_threads();
}
}
#endif
#endif // UNI_GPU
};

Device_class::~Device_class(){
Expand Down
8 changes: 2 additions & 6 deletions src/SparseUniTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ namespace cytnx {
for (cytnx_uint64 i = 0; i < cb_inbonds.size(); i++) {
N_sym = cb_inbonds[i].Nsym();

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 d = 0; d < N_sym * cb_inbonds[i].dim(); d++) {
cb_inbonds[i].qnums()[cytnx_uint64(d / N_sym)][d % N_sym] *=
cb_inbonds[i].type() * bondType::BD_KET;
Expand All @@ -187,9 +185,7 @@ namespace cytnx {
for (cytnx_uint64 i = 0; i < cb_outbonds.size(); i++) {
N_sym = cb_outbonds[i].Nsym();

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 d = 0; d < N_sym * cb_outbonds[i].dim(); d++) {
cb_outbonds[i].qnums()[cytnx_uint64(d / N_sym)][d % N_sym] *=
cb_outbonds[i].type() * bondType::BD_BRA;
Expand Down
8 changes: 2 additions & 6 deletions src/Symmetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ namespace cytnx {
const std::vector<cytnx_int64> &inL,
const std::vector<cytnx_int64> &inR) {
out.resize(inL.size() * inR.size());
#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 i = 0; i < out.size(); i++) {
out[i] = inL[cytnx_uint64(i / inR.size())] + inR[i % inR.size()];
}
Expand Down Expand Up @@ -146,9 +144,7 @@ namespace cytnx {
const std::vector<cytnx_int64> &inL,
const std::vector<cytnx_int64> &inR) {
out.resize(inL.size() * inR.size());
#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 i = 0; i < out.size(); i++) {
out[i] = (inL[cytnx_uint64(i / inR.size())] + inR[i % inR.size()]) % (this->n);
}
Expand Down
4 changes: 1 addition & 3 deletions src/backend/Storage_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,9 +989,7 @@ namespace cytnx {
void Storage_base::_cpy_bool(void *ptr, const std::vector<cytnx_bool> &vin) {
bool *tmp = static_cast<bool *>(ptr);

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 i = 0; i < vin.size(); i++) {
tmp[i] = vin[i];
}
Expand Down
28 changes: 7 additions & 21 deletions src/backend/linalg_internal_cpu/Abs_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace cytnx {
cytnx_double *_out = (cytnx_double *)out->Mem;
cytnx_complex128 *_ten = (cytnx_complex128 *)ten->Mem;

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 n = 0; n < Nelem; n++) {
_out[n] = std::abs(_ten[n]);
}
Expand All @@ -27,9 +25,7 @@ namespace cytnx {
cytnx_float *_out = (cytnx_float *)out->Mem;
cytnx_complex64 *_ten = (cytnx_complex64 *)ten->Mem;

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 n = 0; n < Nelem; n++) {
_out[n] = std::abs(_ten[n]);
}
Expand All @@ -40,9 +36,7 @@ namespace cytnx {
cytnx_double *_out = (cytnx_double *)out->Mem;
cytnx_double *_ten = (cytnx_double *)ten->Mem;

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 n = 0; n < Nelem; n++) {
_out[n] = std::abs(_ten[n]);
}
Expand All @@ -53,9 +47,7 @@ namespace cytnx {
cytnx_float *_out = (cytnx_float *)out->Mem;
cytnx_float *_ten = (cytnx_float *)ten->Mem;

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 n = 0; n < Nelem; n++) {
_out[n] = std::abs(_ten[n]);
}
Expand All @@ -67,9 +59,7 @@ namespace cytnx {
cytnx_int64 *_out = (cytnx_int64 *)out->Mem;
cytnx_int64 *_ten = (cytnx_int64 *)ten->Mem;

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 n = 0; n < Nelem; n++) {
_out[n] = std::abs(_ten[n]);
}
Expand All @@ -81,9 +71,7 @@ namespace cytnx {
cytnx_int32 *_out = (cytnx_int32 *)out->Mem;
cytnx_int32 *_ten = (cytnx_int32 *)ten->Mem;

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 n = 0; n < Nelem; n++) {
_out[n] = std::abs(_ten[n]);
}
Expand All @@ -95,9 +83,7 @@ namespace cytnx {
cytnx_int16 *_out = (cytnx_int16 *)out->Mem;
cytnx_int16 *_ten = (cytnx_int16 *)ten->Mem;

#ifdef UNI_OMP
#pragma omp parallel for schedule(dynamic)
#endif
#pragma omp parallel for schedule(dynamic)
for (cytnx_uint64 n = 0; n < Nelem; n++) {
_out[n] = std::abs(cytnx_double(_ten[n]));
}
Expand Down
Loading
Loading