Search code examples
fortranmpiopenmpopenmpi

Unable to compile MPI program with OpenMP with OpenMPI


I am trying to compare solvers with one of them being parallelized in OpenMP; Solvers are all running in parallel under OpenMPI using Fixed Form Fortran 77; mpif77 does not let me link the object files with the -fopenmp switch; Make does not create the executable. I tried to compile the OpenMP source files separately with gfortran and then tried to link them with mpif77 - does not work; When I do not use the switch it throws the common error:

Undefined symbols for architecture x86_64:
  "_GOMP_parallel", referenced from:
      _parmatdiff_ in matdiff.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [solvercomp] Error 

1

My question is does OpenMPI support OpenMP and if yes, how do I ensure that 'make' links object files created to functions in OpenMP libraries?

Here is a copy of my makefile:

SOURCES = solvcomp.f matdiff.f seqjacobi.f seqconjgrad.f parsor.f
FCC = mpif77
MPIRUN = mpirun
OBJECTS = $(SOURCES:.f=.o)
TARGET = soln
FFLAGS = -o
CFLAGS = -c
NP = 4

all: $(TARGET) clean

$(TARGET): $(OBJECTS)
        $(FCC) $(FFLAGS) $(TARGET) $(OBJECTS)

$(OBJECTS): $(SOURCES)
        $(FCC) $(CFLAGS) $(SOURCES)

clean:
    rm -rf *.o *.dSYM

Solution

  • Your link command is bogus

    mpif77 -o -fopenmp a.out foo.o
    

    Try

    LDFLAGS='-fopenmp -o'
    

    As far as I am concerned, having -o in your LDFLAGS looks pretty messed up in the first place.