Example won't link

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)
Post Reply
jrm4412
Posts: 5
Joined: Wed Nov 05, 2014 11:29 pm

Example won't link

Post by jrm4412 » Wed Nov 05, 2014 11:34 pm

Hi guys.

I'm trying to get the example up and running on a Fedora Core 20 machine with Intel compilers (mkl 11.2) and CUDA 6.5, but I'm having some trouble with linking. This is what I'm running to compile and link:
icc -DADD_ -openmp -I/usr/local/magma/include -I/usr/local/cuda-6.5/include -I/opt/intel/composer_xe_2015.0.090/mkl/include -Wall -c -o example.o example.c
icc -DADD_ -openmp -I/usr/local/magma/include -I/usr/local/cuda-6.5/include -I/opt/intel/composer_xe_2015.0.090/mkl/include -Wall -c -o zfill.o zfill.c
icc -DADD_ -openmp -L/usr/local/magma/lib -L/opt/intel/composer_xe_2015.0.090/mkl/lib/intel64 -L/usr/local/cuda-6.5/lib64 -lmagma -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lpthread -lcublas -lcudart -lstdc++ -lm -Wall -o example example.o zfill.o
The .o files compile without error, but the executable won't build. I get the following errors:
icc: warning #10315: specifying -lm before files may supersede the Intel(R) math library and affect performance
example.o: In function `main':
example.c:(.text+0x39): undefined reference to `magma_init'
example.c:(.text+0x65): undefined reference to `magma_malloc_cpu'
example.c:(.text+0x74): undefined reference to `magma_malloc_cpu'
example.c:(.text+0x83): undefined reference to `magma_malloc_cpu'
example.c:(.text+0xfa): undefined reference to `magma_zgesv'
example.c:(.text+0x125): undefined reference to `magma_free_cpu'
example.c:(.text+0x12f): undefined reference to `magma_free_cpu'
example.c:(.text+0x139): undefined reference to `magma_free_cpu'
example.c:(.text+0x164): undefined reference to `magma_malloc'
example.c:(.text+0x173): undefined reference to `magma_malloc'
example.c:(.text+0x182): undefined reference to `magma_malloc_cpu'
example.c:(.text+0x201): undefined reference to `magma_zgesv_gpu'
example.c:(.text+0x23c): undefined reference to `magma_free_internal'
example.c:(.text+0x255): undefined reference to `magma_free_internal'
example.c:(.text+0x25f): undefined reference to `magma_free_cpu'
example.c:(.text+0x264): undefined reference to `magma_finalize'
example.o: In function `cpu_interface':
example.c:(.text+0x2e7): undefined reference to `magma_malloc_cpu'
example.c:(.text+0x2ff): undefined reference to `magma_malloc_cpu'
example.c:(.text+0x310): undefined reference to `magma_malloc_cpu'
example.c:(.text+0x37d): undefined reference to `magma_zgesv'
example.c:(.text+0x3a8): undefined reference to `magma_free_cpu'
example.c:(.text+0x3b2): undefined reference to `magma_free_cpu'
example.c:(.text+0x3bc): undefined reference to `magma_free_cpu'
example.o: In function `gpu_interface':
example.c:(.text+0x428): undefined reference to `magma_malloc'
example.c:(.text+0x43f): undefined reference to `magma_malloc'
example.c:(.text+0x450): undefined reference to `magma_malloc_cpu'
example.c:(.text+0x4b9): undefined reference to `magma_zgesv_gpu'
example.c:(.text+0x4f3): undefined reference to `magma_free_internal'
example.c:(.text+0x50c): undefined reference to `magma_free_internal'
example.c:(.text+0x516): undefined reference to `magma_free_cpu'
zfill.o: In function `zfill_matrix_gpu':
zfill.c:(.text+0x217): undefined reference to `magma_malloc_cpu'
zfill.c:(.text+0x310): undefined reference to `magma_zsetmatrix_internal'
zfill.c:(.text+0x31e): undefined reference to `magma_free_cpu'
zfill.o: In function `zfill_rhs_gpu':
zfill.c:(.text+0x3a7): undefined reference to `magma_malloc_cpu'
zfill.c:(.text+0x4a0): undefined reference to `magma_zsetmatrix_internal'
zfill.c:(.text+0x4ae): undefined reference to `magma_free_cpu'
Everything in the 'testing' folder builds and runs properly. What am I missing here?

mgates3
Posts: 918
Joined: Fri Jan 06, 2012 2:13 pm

Re: Example won't link

Post by mgates3 » Fri Nov 07, 2014 10:53 am

I think the problem is the link order. Notice the compiler warning that you get. gcc doesn't seem to care if object files are last, but apparently icc does. Put object files first, before all the libraries. I changed the example Makefile to have this:

Code: Select all

example: example.o zfill.o
        $(LD) $(LDFLAGS) -o $@ $^ $(MAGMA_LIBS)
which should execute this:

Code: Select all

icc -DADD_ -openmp -Wall -o example example.o zfill.o -L/usr/local/magma/lib -L/opt/intel/composer_xe_2015.0.090/mkl/lib/intel64 -L/usr/local/cuda-6.5/lib64 -lmagma -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -lpthread -lcublas -lcudart -lstdc++ -lm

jrm4412
Posts: 5
Joined: Wed Nov 05, 2014 11:29 pm

Re: Example won't link

Post by jrm4412 » Fri Nov 07, 2014 4:23 pm

That did it. Thanks!

Post Reply