Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Spanky Deluxe

macrumors demi-god
Original poster
Mar 17, 2005
5,282
1,745
London, UK
I'm working on some code that was given me. Due to consistantly getting errors in the fftw3 intel compile I'm now trying to get it to work in a Linux (Fedora) environment. It was originally written in Linux apparently.

Now I don't have a clue what to do with a makefile. I've never had to use one before and I don't get it.

My header of my main file, main.c is as follows:

Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <fftw3.h>
#include "ran.h">

A part of my main program is the following (as an example, I don't know what it does yet):

Code:
uk=fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  vk=fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  wk=fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  uktmp=fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  vktmp=fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  wktmp=fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  omk=fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  nlnsuk=fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  nlnsvk=fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  nlnswk=fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  ek=fftw_malloc((nk+1)*sizeof(double));
  epsk=fftw_malloc((nk+1)*sizeof(double));
  lk=fftw_malloc((nk+1)*sizeof(double));
  sk=fftw_malloc((nk+1)*sizeof(double));
  tk=fftw_malloc((nk+1)*sizeof(double));
  u=fftw_malloc(n*n*n*sizeof(double));
  v=fftw_malloc(n*n*n*sizeof(double));
  w=fftw_malloc(n*n*n*sizeof(double));
  om=fftw_malloc(n*n*n*sizeof(double));
  ak1=fftw_malloc(n*sizeof(double));
  ak2=fftw_malloc(n*sizeof(double));
  ak3=fftw_malloc((n/2+1)*sizeof(double));
  ak1a=fftw_malloc(na*sizeof(double));
  ak2a=fftw_malloc(na*sizeof(double));
  ak3a=fftw_malloc((na/2+1)*sizeof(double));

  p1=fftw_plan_dft_c2r_3d(n,n,n,uktmp,u,FFTW_ESTIMATE);
  p2=fftw_plan_dft_c2r_3d(n,n,n,vktmp,v,FFTW_ESTIMATE);
  p3=fftw_plan_dft_c2r_3d(n,n,n,wktmp,w,FFTW_ESTIMATE);

Now this compiled fine in Xcode but gave memory problems which I narrowed down to fftw3 which is apparently buggy and incomplete for Intel OS X. Putting all this into Eclipse in Linux gave me lots of size errors so I changed the section above to:

Code:
uk=(fftw_complex *)fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  vk=(fftw_complex *)fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  wk=(fftw_complex *)fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  uktmp=(fftw_complex *)fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  vktmp=(fftw_complex *)fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  wktmp=(fftw_complex *)fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  omk=(fftw_complex *)fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  nlnsuk=(fftw_complex *)fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  nlnsvk=(fftw_complex *)fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  nlnswk=(fftw_complex *)fftw_malloc(n*n*(n/2+1)*sizeof(fftw_complex));
  ek=(double *)fftw_malloc((nk+1)*sizeof(double));
  epsk=(double *)fftw_malloc((nk+1)*sizeof(double));
  lk=(double *)fftw_malloc((nk+1)*sizeof(double));
  sk=(double *)fftw_malloc((nk+1)*sizeof(double));
  tk=(double *)fftw_malloc((nk+1)*sizeof(double));
  u=(double *)fftw_malloc(n*n*n*sizeof(double));
  v=(double *)fftw_malloc(n*n*n*sizeof(double));
  w=(double *)fftw_malloc(n*n*n*sizeof(double));
  om=(double *)fftw_malloc(n*n*n*sizeof(double));
  ak1=(double *)fftw_malloc(n*sizeof(double));
  ak2=(double *)fftw_malloc(n*sizeof(double));
  ak3=(double *)fftw_malloc((n/2+1)*sizeof(double));
  ak1a=(double *)fftw_malloc(na*sizeof(double));
  ak2a=(double *)fftw_malloc(na*sizeof(double));
  ak3a=(double *)fftw_malloc((na/2+1)*sizeof(double));

  p1=fftw_plan_dft_c2r_3d(n,n,n,uktmp,u,FFTW_ESTIMATE);
  p2=fftw_plan_dft_c2r_3d(n,n,n,vktmp,v,FFTW_ESTIMATE);
  p3=fftw_plan_dft_c2r_3d(n,n,n,wktmp,w,FFTW_ESTIMATE);

This cured the mismatch errors but now my compile is giving me errors such as "undefined reference to 'fftw_malloc'" for the first part of the above code and "undefined reference to 'fftw_plan_dft_c2r_3d'" for the last little section.

My makefile at the moment is as follows:

Code:
makefile:
all: main

LIB = -L/usr/local/lib -fftw3 -llapack -lblas -lg2c -static

main : main.o
   g++ -g -o main main.o

main.o : main.c
   g++ -c -g main.c

clean :
   -del main.o

I'm pretty sure my problem is that I'm not linking the fftw3 library properly in the makefile. I made that makefile by finding snippets online and shoving them together, I really don't know how they work at all. To work with, I was given a main.c file to work with and the ran.h file it calls - there are also *no* comments throughout the entire sixteen pages of code, so this is driving me nuts. I just want to get it working as is, just one copy of it working would let me have a base to work out what everything does etc etc. Can anyone help!!
 

Spanky Deluxe

macrumors demi-god
Original poster
Mar 17, 2005
5,282
1,745
London, UK
Ok, I worked out how to get Eclipse to make its own makefile. I still get the same errors though. Its as if the code sees the fftw3.h header file but can't find the libfftw3.a library file even though I've listed it in the library search path of the gcc c linker on the project properties page.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.