Installing 1.8.1 and 1.9 with AD and R

164 views
Skip to first unread message

Geoffrey Phipps

unread,
Jul 12, 2022, 5:08:49 PM7/12/22
to TMB Users

Hi,

  We are having tremendous problems building a stable installation of TMB with R 4.2.*

We build a linux container that includes R 4.2, Intel MKL, and TMB 1.7.16. We have been doing this successfully for many years with previous versions of R, although building a new image has always been troublesome. The hardest part is getting TMB to link.

Currently we are unable to create a usable implementation. Our problems are:

Building with TMB 1.8.1 failed because there were undefined symbols. We modified the Makefile to get around that, but then the model would not converge, even though it converged in  a build from several years ago using R 3.6.1

If we use a non-optimized (standard without AD) build it converges, it fails on an optimized (TMB with AD) build. The non-optimized build is too slow.

The libraries we used in the linking command we used in this case was:

"-Wl,--no-as-needed -lmkl_gf_lp64 -Wl,--start-group -lmkl_gnu_thread  -lmkl_core  -Wl,--end-group -fopenmp  -ldl -lpthread -lm \"

 

Builds with 1.9.0 crashed due to a double memory-free error:

 

> obj <- MakeADFun(tmb_data, tmb_par, random = c("B", paste0("re", 1:4)), DLL = paste0("mod_", model), map = map)
4 regions found.
Using 1 threads
double free or corruption (!prev)
/ihme/singularity-images/rstudio/shells/interactiveR.sh: line 91: 1908998 Aborted singularity exec -B '/mnt,/tmp/singularity_limingxu/1908979:/tmp' /tmp/image_cache/ba98d68b123191aa326c93bac6bf1e3b.img /bin/bash -c "umask 002 && /usr/local/bin/R"

A build with oipenblas is easy to make, but our code includes mkl.h from Intel, so that is of no use to us.

We tried using gdb to find the memory error but could not.

What does SuiteSparse do? We suspect that it and metis might be part of the problem

So, we have three problems

  1. Why are models no longer converging using AD?
  2. What can we do about the memory error?
  3. In general, how can we create a useable installation?

Kasper Kristensen

unread,
Jul 13, 2022, 5:39:05 AM7/13/22
to TMB Users

INSTALL

To build a stable TMB for optimal performance with a recent R on a Linux system you should always do (and nothing else):

git clone https://github.com/kaskr/adcomp
cd adcomp
make install-metis-full

The applied BLAS is set by the R installation:

R CMD config BLAS_LIBS

If this is not what you want then re-install R appropriately from source.

TEST

cd adcomp/tmb_examples

Check timings of a relevant model (using BLAS and METIS orderings):
make ar1_4D
(Should run in less than 4 seconds.)

Also check a model using parallel templates:
OMP_NUM_THREADS=8 make transform_parallel
(Did it split the work in 8 parallel chunks?)

Finally check for correctness:
make report
cat REPORT.md

ADAPT OLD MODELS

Some minor changes were made in TMB version 1.9.0 on how to control the number of OpenMP threads. I see from your model output '4 regions found using 1 thread', probably because you have omp_* in your cpp file? This is no longer supported (or needed). You have to set the number of threads from the R script explicitly using 'openmp(nthreads)' or allow the max to be used by setting 'openmp(max=TRUE)'. Otherwise only 1 thread will be used.

Make sure that linker errors of your model are not due to old incompatible object files (rm *.o).

Geoffrey Phipps

unread,
Jul 13, 2022, 12:57:44 PM7/13/22
to TMB Users
Thanks, we will try this today
Reply all
Reply to author
Forward
0 new messages