TinkerTools / tinker

Tinker: Software Tools for Molecular Design
https://dasher.wustl.edu/tinker/
Other
130 stars 61 forks source link

Building tinker from source in ARM64 MacOS #99

Closed Fplanas92 closed 2 years ago

Fplanas92 commented 2 years ago

Dear developers,

When building Tinker from source in a MacOS laptop running BigSur with an ARM64 chip I get this error: ld: library not found for -lfftw3_threads

I have checked and in the /tinker/fftw/lib folder there is not a fftw3_threads library. There are only four files, which feels wrong. cmake libfftw3.a
libfftw3.la pkgconfig

The FFTW libraries were build with the following commands: ./configure --with-slow-timer --host=arm-macos-darwin --enable-single --enable-neon --prefix=/Applications/tinker/ make make install The process finished without any error, but yet the libraries seem incomplete.

It might be that I am missing some key flags when building libraries, because I know that the process of building them is sensitive to the OS and architecture of the machine, but I am out of ideas. If you are familiarised with this error, or you have experience in building Tinker in other machines with same OS and architecture, I would appreciate some help.

Very appreciated.

Ferran

Many thanks, Ferran

jayponder commented 2 years ago

Hi, You should read the instructions in the file ~/tinker/fftw/0README. You need to add the flags --enable-threads and --enable-openmp to your configure command when you build FFTW. If the FFTW build completes correctly, you will then have libfftw3_omp.a and libfftw3_threads.a in ~/tinker/fftw/lib, in addition to libfftw3.a.

In general, always look for the 0README files in the various Tinker directories. These are files added by the Tinker developers.

Let us know if you still have problems...

Fplanas92 commented 2 years ago

Hi Jay,

Thanks for you answer. I have now successfully build the libraries, but I still get the exact same error. ld: library not found for -lfftw3_threads

Although the file is there now. -rwxr-xr-x 1 fplpa staff 905 Dec 20 14:10 libfftw3f.la -rw-r--r-- 1 fplpa staff 1338856 Dec 20 14:10 libfftw3f.a drwxr-xr-x 3 fplpa staff 96 Dec 20 14:10 cmake drwxr-xr-x 3 fplpa staff 96 Dec 20 14:10 pkgconfig -rwxr-xr-x 1 fplpa staff 972 Dec 20 14:10 libfftw3f_threads.la -rwxr-xr-x 1 fplpa staff 969 Dec 20 14:10 libfftw3f_omp.la -rw-r--r-- 1 fplpa staff 34696 Dec 20 14:10 libfftw3f_threads.a -rw-r--r-- 1 fplpa staff 31040 Dec 20 14:10 libfftw3f_omp.a

Am I missing something else?

Thanks, Ferran

jayponder commented 2 years ago

The problem is seen in the file listing you provide above. You don't have "libfftw3_threads.a", instead you have "libfftw3f_threads.a". Note the extra "f" in the name. I had not seen this before. But from a simple Google search it appears that the extra "f" means the libraries are single precision.

You want the double precision libraries for FFTW, as the entire Tinker CPU source code is written using double precision math. Try simply removing the "--enable-single" flag from your configure command, and rebuilding FFTW. Again, I'd encourage you to follow the instructions in the ~/tinker/fftw/0README file exactly.

jayponder commented 2 years ago

Upon further checking, you will probably also need to remove the "--enable-neon" flag. As I understand it, this flag is specific for ARM processors, and if --enable-neon is used, then --enable-single must also be used. If you leave out both of these flags, then you may (unsure?) generate scalar libraries. But at least Tinker should run. And at least for small through medium-sized systems, using scalar FFT code does not have a very big effect on overall speed.

I have access to one of the newer ARM-based Macs, and will work on building Tinker on it to see how FFTW behaves. But I may not get to this for a few days.

Let us know if removing --enable-neon and --enable-single gets Tinker running.

(I would note here that CPU Tinker is slow. If you want to run "production" calculations, then once you have Tinker working you should consider switching to Tinker9, our GPU-enabled version of Tinker for use with NVIDIA GPUs. Of course you won't be using NVIDIA GPUs under macOS, as they are no longer supported due to the stupid fighting between Apple and NVIDIA.)

Fplanas92 commented 2 years ago

Hi Jay,

You were spot on. I removed both --enable-single and --enable-neon and I could build the dual precision libraries. There was still something I needed to change when building FFTW

./configure --with-slow-timer --host=arm-macos-darwin --enable-threads --enable-openmp --prefix=/Applications/tinker/fftw CC=gfortran Without the CC=gfortran, the openmp is not activated.

I think I now have a functional tinker. At least, the tests I have done have worked fine.

Thanks for your help,

Ferran

jayponder commented 2 years ago

Glad to help, and I'm happy you now have Tinker running!

As you might have noticed, you really only need either libfftw3_threads.a or libfftw3_omp.a, but not both. The Tinker Makefile is set to use libfftw3_threads.a since we have found it to be more "consistent" in performance than the OpenMP library. So you could probably just leave out the --enable-openmp and CC=gfortran, and the Tinker build should still work.

Also, as you may be aware, the currently available gcc and gfortran are not (yet) native for Apple Silicon chips. So the Tinker you have built will be using Apple's Rosetta 2 emulation, and probably won't have the full speed of a native app.