Repository navigation
Description
When compiling OpenBLAS on a very fast machine and a warm ccache using a parallel build, it is very easy to get two ar processes modifying libopenblas64_p-r0.3.0.dev.a. This manifests in symbols randomly "disappearing" from libopenblas for some builds, because two ar processes read in the .a file, they both modify it to add in their object files, then both save it.
This most often happens for the lapack-netlib/TESTING/MATGEN symbols, which are not the most critical of symbols (and so sometimes go unnoticed when they are left undefined), but which always fails on OSX due to the symbol renaming that we do on that platform. This manifests itself in messages that look like the following:
/Users/sabae/src/julia/deps/scratch/objconv/objconv @objconv.def ../libopenblas64_p-r0.3.0.dev.a ../libopenblas64_p-r0.3.0.dev.a.osx.renamed
Warning 1106: Symbol %s not found. Modification of this symbol failed_clahilb_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clakf2_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clarge_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clarnd_
Warning 1106: Symbol %s not found. Modification of this symbol failed_claror_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clarot_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clatm1_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clatm2_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clatm3_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clatm5_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clatm6_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clatme_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clatmr_
Warning 1106: Symbol %s not found. Modification of this symbol failed_clatmt_
Warning 1106: Symbol %s not found. Modification of this symbol failed_dlahilb_
Warning 1106: Symbol %s not found. Modification of this symbol failed_dlakf2_
Warning 1106: Symbol %s not found. Modification of this symbol failed_dlaran_
Warning 1106: Symbol %s not found. Modification of this symbol failed_dlarge_
Warning 1106: Symbol %s not found. Modification of this symbol failed_dlarnd_
Warning 1106: Symbol %s not found. Modification of this symbol failed_dlaror_
Warning 1106: Symbol %s not found. Modification of this symbol failed_dlarot_
Warning 1106: Symbol %s not found. Modification of this symbol failed_dlatm1_
Warning 1106: Symbol %s not found. Modification of this symbol failed_dlatm2_
Warning 1106: Symbol %s not found. Modification of this symbol failed_dlatm3_
...
Followed by this linker error:
ccache gfortran -mmacosx-version-min=10.8 -march=x86-64 -Wa,-q -m64 -O2 -fPIC -O2 -m128bit-long-double -Wall -m64 -fdefault-integer-8 -fPIC -all_load -headerpad_max_install_names -install_name "/Users/sabae/src/julia/deps/scratch/openblas-939452ea9dcb57abdcc3f1278c6db68a4690465/exports/../libopenblas64_p-r0.3.0.dev.dylib" -dynamiclib -o ../libopenblas64_p-r0.3.0.dev.dylib ../libopenblas64_p-r0.3.0.dev.a.osx.renamed -Wl,-exported_symbols_list,osx.def -L/usr/local/Cellar/gcc/8.1.0/lib/gcc/8/gcc/x86_64-apple-darwin17.5.0/8.1.0 -L/usr/local/Cellar/gcc/8.1.0/lib/gcc/8/gcc/x86_64-apple-darwin17.5.0/8.1.0/../../.. -L/usr/local/Cellar/gcc/8.1.0/lib/gcc/8/gcc/x86_64-apple-darwin17.5.0/8.1.0 -L/usr/local/Cellar/gcc/8.1.0/lib/gcc/8/gcc/x86_64-apple-darwin17.5.0/8.1.0/../../.. -lgfortran -lSystem -lquadmath -lm -lSystem -lgfortran -lSystem -lquadmath -lm -lSystem
Undefined symbols for architecture x86_64:
"_clagge_64_", referenced from:
_LAPACKE_clagge_work64_ in libopenblas64_p-r0.3.0.dev.a.osx.renamed(lapacke_clagge_work.o)
"_claghe_64_", referenced from:
_LAPACKE_claghe_work64_ in libopenblas64_p-r0.3.0.dev.a.osx.renamed(lapacke_claghe_work.o)
"_clagsy_64_", referenced from:
_LAPACKE_clagsy_work64_ in libopenblas64_p-r0.3.0.dev.a.osx.renamed(lapacke_clagsy_work.o)
"_clahilb_64_", referenced from:
-exported_symbol[s_list] command line option
"_clakf2_64_", referenced from:
-exported_symbol[s_list] command line option
....
I think it is necessary to do something to prevent the Makefiles from running these ar invocations simultaneously; perhaps by forcing an order-only dependency chain between them.
This is further exacerbated by lapack-netlib/TESTING/MATGEN/Makefile, which has the following logic:
../../$(TMGLIB): $(ALLOBJ)
$(ARCH) $(ARCHFLAGS) $@ $^
$(RANLIB) $@
$(TMGLIB) in this case is libopenblas64_p-r0.3.0.dev.a, and so this says that if libopenblas64_p-r0.3.0.dev.a already exists and is newer than $(ALLOBJ), we don't need to run this ar invocation. This means that if I notice some symbols are missing, and try to run make -C lapack-netlib tmglib, it just says "nothing to do".
Activity
staticfloat commentedon Jul 13, 2018
I'm getting around the second problem by setting those targets that perform
arcommands as.PHONY, but that's not necessarily the correct way; I would argue the correct way would be to have eacharinvocation output a separate.afile, then have one giantarcommand to glom them all together.staticfloat commentedon Jul 14, 2018
I should note that the
.PHONYfix must be applied to multipleMakefiles:lapack-netlib/TESTING/MATGEN:.PHONY: ../../$(TMGLIB)lapack-netlib/LAPACKE/utils/Makefile:.PHONY: liblapack-netlib/LAPACKE/src/Makefile:.PHONY: ../../$(LAPACKELIB)lapack-netlib/SRC/Makefile:.PHONY: ../$(LAPACKLIB)martin-frbg commentedon Jul 14, 2018
If I understand you correctly, wouldn't that be a bug in (parallel)makerather than the Makefile ?martin-frbg commentedon Jul 14, 2018
On Linux a stopgap solution could be to put an
flockon the relevant AR invocations, but that utility (though not the system call of the same name) does not seem to be available elsewhere. Creating separate .a files with a final ar run at the end is probably the best option (and might fix other deficiencies mentioned earlier, like #705)staticfloat commentedon Jul 17, 2018
Agreed. Yes, it looks like Tony's issue is very much related. To be honest, I'm amazed this has worked as well as it has for so long. It must be that we're finally getting machines that can trigger these race conditions more reliably as they get faster and faster. :P
martin-frbg commentedon Jul 17, 2018
Looks like it, yes. I wonder if adding
netlibto the existing.NOTPARALLELline in the Makefile would be enough for a quick-and-dirty fix. The main problem is probably that OpenBLAS sets all of LAPACKLIB, LAPACKELIB and TMGLIB to itself in make.inc, making it impossible formaketo notice the potential conflict.martin-frbg commentedon Jul 19, 2018
Unfortunately there does not appear to be a portable way to
have one giant ar command to glom them all together(except by first unpacking them all again, which does not look that attractive to me).staticfloat commentedon Jul 19, 2018
Yeah, you're right. I would have thought this would be easier, but I guess not. I agree, unpacking everything seems like a large annoyance.
How hard would it be to have a single
arcommand that just reads from all dependent.ofiles and assembles the one giant.afile directly?martin-frbg commentedon Jul 19, 2018
That would probably expand to a huge command line, possibly causing new problems (of the "argument list too long" kind) and we'd probably still need intermediate .a files to run the tests.
staticfloat commentedon Jul 19, 2018
If we can expand the required toolset to include
libtool, it looks like the following can do all the work for us:That program is pretty common on OSX and Linux; what kinds of other platforms do we need to care about? For windows, I'm assuming you're using a toolchain similar to
mingw32, solibtoolmay not be too hard to come by....martin-frbg commentedon Jul 19, 2018
Android, possibly AIX, the various BSD and SunOS/Solaris derivatives ... on Windows mingw is not a given either, as there is (limited) support for a pure MSVC build if I am not mistaken. So I am not sure if the libtool solution would be more portable than
ar -Mwith MRI commands ?staticfloat commentedon Jul 19, 2018
The problem with MRI commands is that the default
aron OSX is the BSDarwhich doesn't support MRI commands. If we requirellvm-ar, that does seem to support MRI commands, but it doesn't come by default on OSX machines (or FreeBSD, I believe). :(The way this is usually done is to do
ar -r big.a one.o,ar -r big.a two.o, etc.... That's actually what we do now, the problem is just that we have multiple targets that are dumping into the samebig.a.I think we can have a surprisingly simple solution actually; we create separate
.afiles out of each subproject and have those separate.afiles depend on the.ofiles in each subproject, so that we have a clean dependency chain that causes rebuilds of the larger.afiles properly. Then, we have the main overall giant library depend on those.afiles to setup the dependency chain properly, but then we don't actually use the.afiles themselves, but just directly have a bunch ofar -rinvocations. E.g.:libopenblas.a: subproject1.a subproject2.a ... ar -r libopenblas.a <.o files for subproject 1...> ar -r libopenblas.a <.o files for subproject 2...>This way, we ensure that any time we need to modify
libopenblas.awe relink everything so we never get into the weird situation wherelibopenblas.acontains only a subset of subprojects, and also we ensure that the dependency chain is clean such that changingfoo.cwill causefoo.oto be rebuilt, which will causesubproject_foo.ato be rebuilt, which will finally causelibopenblas.ato be rebuilt, which is what we need.dev-zero commentedon Oct 1, 2018
Since I've been looking into this when encountering #1213: I fail to see how the
arprocess can run in parallel since OpenBLAS' mainMakefile(in 0.3.3) explicitly runs the targets after each other:staticfloat commentedon Oct 1, 2018
Within each of those targets however, is the chance for parallelism. Such as here: https://github.com/xianyi/OpenBLAS/blob/develop/lapack-netlib/TESTING/MATGEN/Makefile#L60-L78
dev-zero commentedon Oct 1, 2018
@staticfloat not really, as far as I understand
make: OpenBLAS calls that makefile (actually, it calls one intermediate makefile, but with the same effect) without a specific target, so the first target will be picked, which isall, which depends on../../$(TMGLIB). As a prerequisite for../../$(TMGLIB), it builds everything in$(ALLOBJ), thenmakechecks whether or not any of the just built prerequisites is newer than../../$(TMGLIB)and executes$(ARCH) $(ARCHFLAGS) $@ $^if they are. If you have a fast system and a filesystem with no sub-second resolution in the timestamps,../../$(TMGLIB)and the objects in$(ALLOBJ)might have the samemtimeand therefore../../$(TMGLIB)does not get updated. But thesingle,complex, etc. are never executed.martin-frbg commentedon Oct 2, 2018
@dev-zero while the
single,complexetc. sub-targets are not executed, wouldn'tmakebe able to build the CMATGEN, DMATGEN,.. parts of ALLOBJ in parallel ? (Else I am not sure how/why disabling parallel make would be able to solve this)dev-zero commentedon Oct 2, 2018
@martin-frbg as far as I understood
make, it will first resolve the variables, such that we have the equivalent of:the objects
slatms.o, ... are then built in parallel, but this does not matter at all since they have different names. And only after all of them are built,makewill check their timestamps against the target and based on that run the commands to update the target.The error messages here are slightly different due to the tools being used for linking being different, but I would say this is the same issue as in #1213. In fact, OpenBLAS is not alone on this and it seems that Apple's APFS or HFS+ is to blame: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81797 ... APFS has a bug and HFS+ has only 1s time stamp resolution (see https://gcc.gnu.org/ml/gcc-bugs/2017-08/msg01319.html).
The solution: disable parallel builds on macOS or make all the
../../$(TMGLIB): ...targets.PHONYto force make to always update them (as already proposed). Since we explicitly run those targets in serial in OpenBLASMakefile, we actually know that there will never be more than one process updating../../$(TMGLIB)at the same time, so that should be safe.staticfloat commentedon Oct 2, 2018
Ah, my bad. Thanks @dev-zero. It's been a while since I looked at this so I don't remember precisely which targets are being built in parallel.
Your understanding is correct.
This will greatly increase compile times for us. I'd rather not do that.
This should work, as long as
aris smart enough to not complain when you are trying to add symbols into an archive that already exist. Additionally, this means that when we runmakeon OSX, it will never do nothing; it will always re-runar.martin-frbg commentedon Oct 2, 2018
IIRC all
arinvocations are with flags set to-ror probably-rusoarshould not complain (?)fix parallel build issues with APFS/HFS+/ext2/3 in netlib-lapack