使用Travis CI测试MPI项目(使用Cmake编译)



我正在学习使用Travis CI进行持续集成。我的项目需要使用MPI库,所以我让Travis安装OpenMPI并使用cmake编译代码。这是我的.travis.yml文件


## configure Travis to use the right compiler
dist: trusty
sudo: false # do not need sudo support
language: cpp
# Cacnhing dependencies
cache:
directories:
- openmpi-4.0.2   # build mpi only need to done onece

# MPI project
before_install:
- sh ./get_openmpi.sh 
# save listing branches (specifies the branch to build) 
branches:
only:
- master
- load_balancing 

script:
- mkdir build
- mkdir outputs
- mkdir tests
- cd build
- cmake ..     # configuring cmake in the current build folder

这是我的get_openmpi.sh脚本文件,用于导入所有OpenMPI。我把它安装在openmpi-4.0.2目录中。

#!/bin/sh
# check if OpenMPI is cached from previous build
if [ -f "openmpi/bin/mpirun"]; then
echo "Using cached OpenMPI"
else
echo "Downloading OpenMPI source"
wget https://download.open-mpi.org/release/open-mpi/v4.0/openmpi-4.0.2.tar.gz
tar xfz openmpi-4.0.2.tar.gz
rm openmpi-4.0.2.tar.gz
echo "Configuring and building openmpi"
cd openmpi-4.0.2
./configure --prefix=`pwd`
make -j 4 all
make install
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/lib
cd ..
fi

我的CMakeLists.txt:

cmake_minimum_required(VERSION 3.9)
# name of the project + language
project(2d_wave CXX)
# Bring the headers
include_directories(inc)
# source file
file(GLOB SOURCES "src/*.cpp")
# executable file
add_executable(main ${SOURCES})

# MPI-------------------------------------------------------------------------------------
# find MPI package
find_package(MPI REQUIRED)
if(MPI_NOFOUND)
message(ERROR "MPI is not found. Please check FindMPI.")
endif(MPI_NOFOUND)
#---------------------------------------------------------------------------------------
# libraires links
target_link_libraries(main PUBLIC MPI::MPI_CXX )

但是,cmake无法使用find_package()找到MPI库。我在脚本文件中导出了库路径(我需要这样做吗?(,但没有帮助。

有人能告诉我如何将MPI库链接到cmake吗?非常感谢!

以下是错误信息:

-- The CXX compiler identification is GNU 4.8.4
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at /usr/local/cmake-3.9.2/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
Could NOT find MPI_CXX (missing: MPI_CXX_LIBRARIES MPI_CXX_INCLUDE_PATH)
Call Stack (most recent call first):
/usr/local/cmake-3.9.2/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:377 (_FPHSA_FAILURE_MESSAGE)
/usr/local/cmake-3.9.2/share/cmake-3.9/Modules/FindMPI.cmake:640 (find_package_handle_standard_args)
CMakeLists.txt:23 (find_package)

如果你需要更多信息,你可以在这里查看我的Travis页面。我想在brachload_balancing上测试我的项目。

if [[ ${TRAVIS_OS_NAME} == "linux" ]]; then
CMAKE_URL="http://www.cmake.org/files/v3.5/cmake-3.5.1-Linux-x86_64.tar.gz"
mkdir -p ${DEPS_DIR}/cmake
travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip- 
components=1 -xz -C ${DEPS_DIR}/cmake
export PATH=${DEPS_DIR}/cmake/bin:${PATH} 
fi

最新更新