A.nechi
A.nechi

Reputation: 305

undefined references when using fftw3.3.6 with threads and float enabled

I installed fftw3.3.6 on my Ubuntu 16.04 to test the performance of using this library with thread and float enabled.

Step 1 :

Installed the library with thread and float and SIMD instructions enabled:`

sudo ./configure --enable-float --enable-generic-simd128 --enable-generic-simd256 --enable-threads
make
make install

Step 2 :

I wrote this code (basing on the manual and tutorial) to compute an fft of 1024 points using 4 threads (complex to complex):

#include <stdio.h>
#include <stdlib.h>
#include <fftw3.h>

#include "input.h"

#define         NUMBER_OF_ELEMENTS              1024
#define         NUM_THREADS                     4

void Load_inputs(fftwf_complex* data)
{
   int i;

   for(i=0;i<NUMBER_OF_ELEMENTS;i++)
   {
      data[i][0] = input_data[2 * i];
      data[i][1] = input_data[2 * i + 1];
   }
}


int main()
{
   fftwf_complex array[NUMBER_OF_ELEMENTS];
   fftwf_plan p;
   int i;

   fftwf_init_threads();
   fftwf_plan_with_nthreads(NUM_THREADS);
   p = fftwf_plan_dft(1,NUMBER_OF_ELEMENTS,array,array,FFTW_FORWARD,FFTW_EXHAUSTIVE);
   Load_inputs(array); //function to load input data from input.h file to array[]
   fftwf_execute(p);
   FILE* res = NULL;
   res = fopen("result.txt", "w");
   for ( i = 0; i <1024; i++ )
   {
       fprintf(res,"RE = %f \t IM  = %f\n",array[i][0], array[i][1] );
   }
   fclose(res);
   fftwf_destroy_plan(p);
   fftwf_cleanup_threads();
}

And then, I compiled this program with this makefile.

CC=gcc
CFLAGS=-g3 -c -Wall -O0 -mavx -mfma -ffast-math 

SOURCES=$ test.c
OBJECTS=$(SOURCES:.c=.o)

EXECUTABLE=test


all: $(TASKMAP) $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) 
     $(CC) $(OBJECTS) -o $@ -L -lfftw3f_threads -lfftw3f 

.c.o:
     $(CC) $(CFLAGS) $< -lm -o $@

clean: 
     rm -fr $(OBJECTS) $(EXECUTABLE)

Compilation errors :

After compilation I've got these errors:

gcc test.o -o test -L -lfftw3f_threads -lfftw3f 
//usr/local/lib/libfftw3f.a(mapflags.o): In function `fftwf_mapflags':
mapflags.c:(.text+0x346): undefined reference to `__log_finite'
Makefile:13: recipe for target 'test' failed
//usr/local/lib/libfftw3f.a(trig.o): In function `cexpl_sincos':
trig.c:(.text+0x2c1): undefined reference to `sincos'
//usr/local/lib/libfftw3f.a(trig.o): In function `fftwf_mktriggen':
trig.c:(.text+0x50b): undefined reference to `sincos'
trig.c:(.text+0x653): undefined reference to `sincos'
test.o: In function `main':
/home/anouar/workspace/Thread_example//test.c:27: undefined reference to `fftwf_init_threads'
/home/anouar/workspace/Thread_example//test.c:28: undefined reference to `fftwf_plan_with_nthreads'
/home/anouar/workspace/Thread_example//test.c:40: undefined reference to `fftwf_cleanup_threads'
 collect2: error: ld returned 1 exit status
 make: *** [test] Error 1

Is there something missing, or something wrong that I have did during installation and compilation?

Upvotes: 3

Views: 2049

Answers (2)

Hannes
Hannes

Reputation: 1

In my case, the problems with

undefined reference to `__log_finite'

could be solved by compiling without the -ffast-math option.

Upvotes: 0

Andrew Henle
Andrew Henle

Reputation: 1

Read the fine manual. From the sincos() man page:

Link with -lm.

Using -lm in the compile phase of your program is useless:

.c.o:
     $(CC) $(CFLAGS) $< -lm -o $@

-lm needs to be in the link stage:

$(EXECUTABLE): $(OBJECTS) 
     $(CC) $(OBJECTS) -o $@ -L -lfftw3f_threads -lfftw3f -lm

Upvotes: 1

Related Questions