LadaF / PoisFFT

Free parallel fast Poisson solver. Requires FFTW3 and optionally PFFT.
Other
55 stars 18 forks source link

Makefile compiling #10

Closed Mattiads1 closed 2 years ago

Mattiads1 commented 4 years ago

Hi, I'm trying to linking the library to my source code. I already tested that the library works; I compiled with 'scons test' and run the test case and it works well. Then, I recompiled with 'scons'. It generate a library in in lib/gcc/libpoisfft.so and modules in bin/gcc/*.mod But when I try to link the library to my source code I got this error message:

/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftwf_plan_dft_3d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference toGOMP_parallel' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftw_plan_dft_1d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference toGOMP_single_start' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftwf_plan_r2r_1d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference tofftw_plan_r2r_1d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftwf_plan_dft_2d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference toomp_get_threadnum' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftw_plan_r2r_3d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference tofftw_plan_r2r_2d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftw_plan_dft_2d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference tofftwf_plan_dft_1d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to omp_get_num_threads_' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference tofftwf_plan_r2r_3d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to omp_get_num_threads' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference tofftwf_execute_dft' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftwf_execute_r2r' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference tofftw_execute_dft' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftw_destroy_plan' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference toGOMP_barrier' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftw_plan_with_nthreads' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference tofftw_plan_dft_3d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftw_free' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference tofftw_execute_r2r' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftwf_plan_r2r_2d' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference toomp_get_thread_num' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference to fftw_init_threads' /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: PoisFFT-master/lib/gcc//libpoisfft.so: undefined reference tofftw_malloc'

In my source code I enable poisFFT as shown 'usage_Fortran.txt' This is my Makefile:

FC=gfortran

FFLAGS := -O3 -ffixed-line-length-none -fdefault-real-8

BIG := # -mcmodel=medium DBG :=# -g -traceback OMP := #-openmp

INCLUDE = -I PoisFFT-master/bin/gcc/

LIB = -L PoisFFT-master/lib/gcc/ -lpoisfft

TARGET = flowclub

SRC = param.f90 common.f90 init.f90 bound.f90 chkdiv.f90 mom.f90 forcing.f90 adam.f90 fillps.f90 solverfft.f90 correc.f90 output.f90 main.f90

OBJ = $(SRC:.f90=.so)

all: $(TARGET)

$(TARGET): $(OBJ) $(FC) $(FFLAGS) $(BIG) $(DBG) $(OMP) -o $@ $(OBJ) $(LIB)

.PHONY: clean
clean: rm -f .so .mod $(TARGET)

%.so: %.f90 $(FC) $(INCLUDE) -c -o $@ $(FFLAGS) $(BIG) $(DBG) $(PROF) $(OMP) $<

LadaF commented 4 years ago

This is a linking issue. If you are using the dynamic version of the library you also have to link with libfftw and libfftwf.

Also, PoisFFT is by default compiled with OpenMP enabled. You can either disable it with scons openmp=no or you have to also link with libfftw_omp and libfftwf_omp and also compile your code with OpenMP or link with libgomp. I suggest to start with OpenMP disabled.

LadaF commented 4 years ago

I do not recommend compiling your code with -fdefault-real-8. It may work, but the library was not tested that way. Be sure to use the correct double precision solver.

Mattiads1 commented 4 years ago

Thanks, I follow all your advice and I solved my problem. I'm not very familiar compilation and linking. I have another question. From what I understand by default when I run with 'scons openmp=no', it create a dynamic library. How can I do if I want a static library?

LadaF commented 4 years ago

No, that is not correct. With 'scons openmp=no' you just disable OpenMP, but both libraries are created, one dynamic .so and one static .a. It is up to you and the settings in your Makefile which one of them you will use. Note that you will have to supply the other necessary libraries in both cases.

Mattiads1 commented 4 years ago

I don't find the static .a libary. When I run 'scons openmp=no' it creates two directories: one is bin/gcc/ where the files.mod and files.os are located; the other one is /lib/gcc/ where only the file libpoisfft.so is present.

While when I run 'scons test' it create only one directory: bin/gcc/ where files.mod and files.o are created.

LadaF commented 4 years ago

You are right the line in the [SConstruct] file is commented out. If you want a static library, you can currently comment out line 220, uncomment 221 and remove the lib +.

LadaF commented 4 years ago

I added a new target to SConstruct. You can just do scons static_lib to get the static library.

Mattiads1 commented 4 years ago

Thanks