#=============================================================================#
#=========================== Executables =====================================#
#=============================================================================#
add_custom_target(build-tests-virtual-hmatrix-hmatrix-product)
add_subdirectory(hmatrix_product)
add_dependencies(build-tests-virtual-hmatrix-hmatrix build-tests-virtual-hmatrix-hmatrix-product)

add_executable(Test_hmat_cluster test_hmat_cluster.cpp)
target_link_libraries(Test_hmat_cluster htool)
add_dependencies(build-tests-virtual-hmatrix-hmatrix Test_hmat_cluster)
add_test(NAME Test_hmat_cluster_1 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_cluster)
set(Test_hmat_cluster_1 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=4)
add_test(NAME Test_hmat_cluster_2 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_cluster)
set(Test_hmat_cluster_2 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=2)
add_test(NAME Test_hmat_cluster_4 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_cluster)
set(Test_hmat_cluster_4 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=1)

add_executable(Test_hmat_zero test_hmat_zero.cpp)
target_link_libraries(Test_hmat_zero htool)
add_dependencies(build-tests-virtual-hmatrix-hmatrix Test_hmat_zero)
add_test(NAME Test_hmat_zero_1 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_zero)
set(Test_hmat_zero_1 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=4)
add_test(NAME Test_hmat_zero_2 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_zero)
set(Test_hmat_zero_2 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=2)
add_test(NAME Test_hmat_zero_4 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_zero)
set(Test_hmat_zero_4 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=1)

#=== hmat_to_dense
add_executable(Test_hmat_to_dense test_hmat_to_dense.cpp)
target_link_libraries(Test_hmat_to_dense htool)
add_dependencies(build-tests-virtual-hmatrix-hmatrix Test_hmat_to_dense)
add_test(NAME Test_hmat_to_dense_1 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_to_dense)
set(Test_hmat_to_dense_1 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=4)
add_test(NAME Test_hmat_to_dense_2 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_to_dense)
set(Test_hmat_to_dense_2 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=2)
add_test(NAME Test_hmat_to_dense_3 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_to_dense)
set(Test_hmat_to_dense_4 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=1)
add_test(NAME Test_hmat_to_dense_4 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_to_dense)

add_executable(Test_hmat_to_dense_perm test_hmat_to_dense_perm.cpp)
target_link_libraries(Test_hmat_to_dense_perm htool)
add_dependencies(build-tests-virtual-hmatrix-hmatrix Test_hmat_to_dense_perm)
add_test(NAME Test_hmat_to_dense_perm_1 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_to_dense_perm)
set(Test_hmat_to_dense_perm_1 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=4)
add_test(NAME Test_hmat_to_dense_perm_2 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_to_dense_perm)
set(Test_hmat_to_dense_perm_2 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=2)
add_test(NAME Test_hmat_to_dense_perm_3 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_to_dense_perm)
set(Test_hmat_to_dense_perm_4 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=1)
add_test(NAME Test_hmat_to_dense_perm_4 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_to_dense_perm)

#=== hmat_save
add_executable(Test_hmat_save test_hmat_save.cpp)
target_link_libraries(Test_hmat_save htool)
add_dependencies(build-tests-virtual-hmatrix-hmatrix Test_hmat_save)
add_test(NAME Test_hmat_save COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_save)

#=== local get
add_executable(Test_hmat_local_get test_hmat_local_get.cpp)
target_link_libraries(Test_hmat_local_get htool)
add_dependencies(build-tests-virtual-hmatrix-hmatrix Test_hmat_local_get)
add_test(NAME Test_hmat_local_get_1 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_local_get)
set(Test_hmat_local_get_1 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=4)
add_test(NAME Test_hmat_local_get_2 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_local_get)
set(Test_hmat_local_get_2 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=2)
add_test(NAME Test_hmat_local_get_3 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_local_get)
set(Test_hmat_local_get_4 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=1)
add_test(NAME Test_hmat_local_get_4 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_local_get)

#=== local get
add_executable(Test_hmat_permutation test_hmat_permutation.cpp)
target_link_libraries(Test_hmat_permutation htool)
add_dependencies(build-tests-virtual-hmatrix-hmatrix Test_hmat_permutation)
add_test(NAME Test_hmat_permutation_1 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_permutation)
set(Test_hmat_permutation_1 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=4)
add_test(NAME Test_hmat_permutation_2 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_permutation)
set(Test_hmat_permutation_2 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=2)
add_test(NAME Test_hmat_permutation_3 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_permutation)
set(Test_hmat_permutation_4 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=1)
add_test(NAME Test_hmat_permutation_4 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_permutation)

#=== delay_dense_computation
add_executable(Test_hmat_delay_dense_computation test_hmat_delay_dense_computation.cpp)
target_link_libraries(Test_hmat_delay_dense_computation htool)
add_dependencies(build-tests-virtual-hmatrix-hmatrix Test_hmat_delay_dense_computation)
add_test(NAME Test_hmat_delay_dense_computation_1 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 1 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_delay_dense_computation)
set(Test_hmat_delay_dense_computation_1 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=4)
add_test(NAME Test_hmat_delay_dense_computation_2 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_delay_dense_computation)
set(Test_hmat_delay_dense_computation_2 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=2)
add_test(NAME Test_hmat_delay_dense_computation_3 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 3 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_delay_dense_computation)
set(Test_hmat_delay_dense_computation_4 PROPERTIES ENVIRONMENT OMP_NUM_THREADS=1)
add_test(NAME Test_hmat_delay_dense_computation_4 COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS} ${CMAKE_CURRENT_BINARY_DIR}/Test_hmat_delay_dense_computation)
