Valgrind¶
valgrind is a tool that can help to check for memory errors. See
also Sanitizers for an alternative strategy.
How-to¶
To run valgrind on an executable generated by the chpl compiler:
export CHPL_MEM=cstdlib
export CHPL_TASKS=fifo
export CHPL_RT_NUM_THREADS_PER_LOCALE=450
export CHPL_RE2_VALGRIND_SUPPORT=true
cd $CHPL_HOME
make
chpl <program.chpl>
valgrind ./<program>
This may require clobbering and rebuilding the re2 library:
cd $CHPL_HOME/third-party/re2
make clobber && make
Explanation¶
The above options are needed because not all third-party libraries support
valgrind. In particular:
jemallocdoes not supportvalgrind, which preventsvalgrindfrom accurately tracking allocations/freesqthreadsperforms task-switching in user-space, sovalgrindis not able to keep track of the stack frame correctlyfifoneeds to limit the number of threads to stay below valgrind’s--max-threadsdefault of 500.re2intentionally leaves some memory uninitialized for performance reasons, unlessCHPL_RE2_VALGRIND_SUPPORT=trueis set at build timeGASNet support for
valgrindis experimental at this time – see https://github.com/chapel-lang/chapel/issues/8544 for the current status