简体   繁体   中英

Clang static analysis with MPI

I would like to use Clang's static analyzer for analyzing parallel code, ie, code with needs MPI compiler wrappers. When configuring with CMake, however, I always get

$ scan-build cmake /path/to/source
-- Check for working CXX compiler: /usr/share/clang/scan-build/c++-analyzer
-- Check for working CXX compiler: /usr/share/clang/scan-build/c++-analyzer -- works

and the subsequent compilation ( make ) fails with

/usr/include/some/header.hpp:56:17: fatal error: mpi.h: No such file or directory

#include "mpi.h"

How to properly use scan-build here?

I have not found a way to use the MPI compiler wrappers directly with scan-build . You can however circumvent the wrappers and give the flags to your compiler manually. eg this works for my environment:

$ export CXXFLAGS=`mpicxx --showme:compile`
$ export LDFLAGS=`mpicxx --showme:link`
$ export CXX=`mpicxx --showme:command`
$ scan-build ./configure && scan-build make #Or your cmake equivalent

The --showme: flags seem to differ slightly between versions, but mpicc --showme:help usually gives you a list of commands your specific wrapper supports.

See MPI-Checker/examples :

To invoke the Clang Static Analyzer, it is recommended to use the scan-build package implemented in Python. You can either use the scripts being contained in LLVM trunk ( llvm/tools/clang/tools/scan-build-py/bin ) or install the scripts with pip install scan-build . Note that on make install LLVM copies old Perl versions of the scripts to /usr/local/bin which therefore might overwrite versions installed with pip.

As the MPI wrapper compiler interferes with the scan-build script, it is recommended to invoke the analysis based on a compilation database, generated by intercept-build (make|ninja|...) . Note that databases generated by CMake can differ from those generated by intercept-build. If the compile_commands.json file denotes mpicc|mpic++ as the used compiler, no reports are emitted.

After the compilation database is created, analysis can be triggered with:
analyze-build --enable-checker your.check --use-analyzer /path/to/clang

You need to have a MPI wrapper for your c-compiler. Which means a MPI library compiled with CLang. After you got that, you need to set the c compiler in your build environment to mpicc. This should provide you with correct includes and linking options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM