|
From: Anton P. <po...@un...> - 2012-11-07 14:51:24
|
Hi,
Valgrind is great, and I've no problems using it under Linux.
However, I also must work on a Mac (running Mac OS Lion), and there I do
have couple of problems:
#----------------------------------------------------------------------------------------
1) Native gcc compiler on Mac OS is very old (version 4.2).
BUT if I try to compile Valgrind with newer version (e.g. plain gcc
compiler installed via macports)
it, of course, cannot recognize -arch x86_64 flag, which is native
only for Apple's gcc.
QUESTIONS:
- Is it possible to replace this flag with standard -m64 on Mac OS,
like it's done on Linux?
- Is plain gcc compiler appropriate at all for compiling Valgrind on
Mac OS?
- Is it OK if I use plain gcc compiler for my applications, together
with Valgrind built with Apple's native gcc?
#----------------------------------------------------------------------------------------
2) With native gcc compiler, the MPI wrappers are built without problems
whatsoever.
I configure like this: ./configure --prefix=/opt/valgrind
--enable-only64bit --with-mpicc=mpicc
Valgrind-clean debug version of MPICH2 (see Appendix A) is used for
MPI implementation, and the resulting
wrapper library libmpiwrap-amd64-darwin.so is indeed placed here:
/opt/valgrind/lib/valgrind
The documentation only describes how to use MPI wrappers on Linux,
I've figured out how it must be done on Mac OS (there is no
LD_PRELOAD for example):
Compile like this:
mpicc -g -O0 mpi_prog.c
Run like this:
DYLD_INSERT_LIBRARIES=/opt/valgrind/lib/valgrind/libmpiwrap-amd64-darwin.so
\
DYLD_FORCE_FLAT_NAMESPACE=1 \
MPIWRAP_DEBUG=quiet \
mpirun -n 4 valgrind --dsymutil=yes --tool=memcheck
--log-file=valgrind.log.%p ./a.out
BUT whatever I do I CANNOT get wrappers activated on Mac OS.
Installation/compilation/linking/running is OK, but the
characteristic message:
valgrind MPI wrappers xxxxx: Active for pid xxxxx
valgrind MPI wrappers xxxxx: Try MPIWRAP_DEBUG=help for possible
options
is NEVER get printed to standard output.
I even tried linking wrappers directly against my application like this:
mpicc -g -O0 mpi_prog.c -L/opt/valgrind/lib/valgrind
-lmpiwrap-amd64-darwin
It successfully compiles, links, and after properly setting
DYLD_LIBRARY_PATH, even runs
without complaining, but, but, but with the same result: wrappers
are never activated.
QUESTIONS:
- Why libmpiwrap-amd64-darwin has a non-standard .so, but not
.dylib, extension on Darwin?
- Can wrappers fail because MPI library on Darwin also has .dylib
extension, but not .so,
which is somehow hardcoded in libmpiwrap.c?
- Can wrappers fail, because MPI library is supposed to be an ELF
shared object, which
obviously cannot be the case on Mac OS, since it uses proprietary
Mach-O format?
The wikipedia page http://en.wikipedia.org/wiki/Mach-O says in the
section "Mach-O future"
that since Mac OS 10.6 "Mach-O file has undergone a significant
modification that
causes binaries compiled on a 10.6 computer to be by default only
able to run on a 10.6 computer"
So, it has probably diverged even further from ELF format.
Sorry for the long message, but it's not actually covered by documentation.
Any information/explanation/advice is highly appreciated.
I hope that the following appendices will be useful for those who use
MPI with Valgrind on Mac OS.
Anton
#----------------------------------------------------------------------------------------
Appendix A:
#----------------------------------------------------------------------------------------
"Valgrind-clean" debug version of MPICH2 with shared libraries,
and C, C++, and FORTRAN language support for Mac OS
"Proper" FORTRAN compiler is taken here:
http://cran.r-project.org/bin/macosx/tools/gfortran-4.2.3.dmg
By default it builds 32-bit code, hence -arch x86_64 flags are added to
FORTRAN binding.
Don't forget to add /opt/mpich2-debug to PATH
./configure \
CC=gcc \
CXX=g++ \
F77=gfortran \
FC=gfortran \
FFLAGS="-arch x86_64" \
FCFLAGS="-arch x86_64" \
CPPFLAGS='-I/opt/valgrind/include/valgrind' \
--prefix=/opt/mpich2-debug \
--enable-f77 \
--enable-fc \
--enable-cxx \
--enable-threads=runtime \
--enable-g=dbg,mem,meminit \
--enable-debuginfo \
--enable-shared \
--enable-sharedlibs="osx-gcc" \
--enable-fast=none
#----------------------------------------------------------------------------------------
Appendix B:
#----------------------------------------------------------------------------------------
INSTALL VALKYRIE (GUI FOR VALGRIND)
1) Install macports:
http://www.macports.org/install.php
Use Mac OS X Package (.pkg) Installer
sudo port -v selfupdate
2) Install qt4
sudo port install qt4-mac
3) Install valkyrie
unpack sources
qmake
make
4) Copy valkyrie.app from ./bin/ to Applications directory
Make desktop shortcut (optionally)
#----------------------------------------------------------------------------------------
|
|
From: Sean M. <se...@ro...> - 2012-11-07 16:30:46
|
On Wed, 7 Nov 2012 15:51:10 +0100, Anton Popov said: >1) Native gcc compiler on Mac OS is very old (version 4.2). That's because Apple has switched from gcc to clang. Have you tried just building with the default 'cc' compiler provide by Xcode? Cheers, -- ____________________________________________________________ Sean McBride, B. Eng se...@ro... Rogue Research www.rogue-research.com Mac Software Developer Montréal, Québec, Canada |
|
From: Anton P. <po...@un...> - 2012-11-07 21:55:09
|
On 11/7/12 5:30 PM, Sean McBride wrote: > On Wed, 7 Nov 2012 15:51:10 +0100, Anton Popov said: > >> 1) Native gcc compiler on Mac OS is very old (version 4.2). > That's because Apple has switched from gcc to clang. > > Have you tried just building with the default 'cc' compiler provide by Xcode? > > Cheers, Thanks for suggestion, but no, and I never will. I've spent far too much time playing with Macintosh. I want to stay with gcc, and I don't care what Apple guys think of it. If I'm not able to use plain gcc (at least for my stuff) + mpi + Valgrind on Mac, I will simply use this combination on Linux (inconvenient but not dramatic). But still, I would appreciate a comment on ELF vs. Mach-O and .so vs. .dylib issue. If it's really the cause why MPI wrappers never get activated, a short notice should be added to the documentation to prevent people from trying to build MPI wrappers on Mac OS. > |
|
From: Anton P. <po...@un...> - 2012-11-08 17:11:35
Attachments:
plain_gcc_osx.patch
|
Hi,
plain gcc compiler issue is solved, please consider my patch to valgrind
(attached).
From the directory that CONTAINS original valgrind-3.8.0 directory run
the command:
patch -p0 < plain_gcc_osx.patch
I use gcc-4.7 installed by macports to /opt/local/bin/gcc-mp-4.7
It recognizes Mac "-arch" compiler flags
After patching configure like this (for example):
./configure CC=/opt/local/bin/gcc-mp-4.7 --prefix=/opt/valgrind
--enable-only64bit
After installation valgrind is accessible from prefix directory. For me
it works.
The issue was caused by using __private_extern__, which is now replaced
with equivalent __attribute__((visibility("hidden")))
Anton
|