2 Replies - 1330 Views - Last Post: 20 July 2011 - 05:52 AM Rate Topic: -----

#1 angel84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-July 11

Message Passing Interface (MPI): Undefined symbols error

Posted 20 July 2011 - 03:33 AM

Hi, I'am a beginner with both C++ and MPI. I think I did a simple mistake, even though I cannot find it. So I ask for your help.
I have a Mac Book Pro, and I compiled this code both on terminal (comand line: mpic++) and using xcode.
I receive in both cases a Undefined symbol error, which I report in the following. Can someone help me?
Thank you very much in advance


 
#include <iostream>
#include <mpi.h>

using namespace std;

#define ndata 1000

int main(int argc, char* argv[]){
	
    int i=0;
	MPI::Status status;
    
    float a[ndata];
    float b[ndata];
	
	MPI::Init(argc,argv);
	int me = MPI::COMM_WORLD.Get_rank();
	int nprocs = MPI::COMM_WORLD.Get_size();	
	
    for(i=0;i<ndata;++i){
		a[i] = me;
    } 
    
    if(nprocs>2 && me==0){
		cout << "\n\tThis program must run on 2 processors";
		return 1;
    }
	
    if(me==0){
		MPI::COMM_WORLD.Send(a, ndata, MPI::REAL, 1, 0);
		MPI::COMM_WORLD.Recv(b, ndata, MPI::REAL, 1, 0, status);
    }
    else{
		MPI::COMM_WORLD.Recv(b, ndata, MPI::REAL, 0, 0, status);
		MPI::COMM_WORLD.Send(a, ndata, MPI::REAL, 0, 0);
    }
	
    cout << "\n\tI am task " << me 
	<< "and I have received b(0) = " << b[0] << "\n";
	
	MPI::Finalize();
	return 0;
}





COMMAND LINE:

>mpic++ mpi_srcc.cpp

Undefined symbols:
"MPI::REAL", referenced from:
_main in ccbzr2Mz.o
_main in ccbzr2Mz.o
_main in ccbzr2Mz.o
_main in ccbzr2Mz.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

XCODE ERROR:
i tried to attach it as .rtf file but it does not accept it. If it is needed I'll try to attach it in another format

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Message Passing Interface (MPI): Undefined symbols error

#2 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1676
  • View blog
  • Posts: 3,179
  • Joined: 30-May 10

Re: Message Passing Interface (MPI): Undefined symbols error

Posted 20 July 2011 - 03:41 AM

Well you usually have to specify one or more libraries (read the MPI manual for library names).

Eg.
mpic++ mpi_srcc.cpp -lmpi
which, in the traditional Unix flavour, would link with the libmpi.a library found in /usr/lib

There is also a -L option, if your library file is in a non-standard place.
Was This Post Helpful? 1
  • +
  • -

#3 angel84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-July 11

Re: Message Passing Interface (MPI): Undefined symbols error

Posted 20 July 2011 - 05:52 AM

HI Salem_c,
thank you for your reply!
It is really welcomed! I tried your option, by linking the library that you suggested while compiling
mpic++ mpi_srcc.cpp -lmpi
Undefined symbols:
  "MPI::REAL", referenced from:
      _main in ccAqLifJ.o
      _main in ccAqLifJ.o
      _main in ccAqLifJ.o
      _main in ccAqLifJ.o
ld: symbol(s) not found
collect2: ld returned 1 exit status



I did not tried the -L option.

Anyway I found out my solution, the code magically built itself if I replace MPI::REAL with MPI::INT in

if(me==0){
30
        MPI::COMM_WORLD.Send(a, ndata, MPI::REAL, 1, 0);
31
        MPI::COMM_WORLD.Recv(b, ndata, MPI::REAL, 1, 0, status);
32
    }
33
    else{
34
        MPI::COMM_WORLD.Recv(b, ndata, MPI::REAL, 0, 0, status);
35
        MPI::COMM_WORLD.Send(a, ndata, MPI::REAL, 0, 0);
36
    }



SO it works. Why? It seems very strange. I checked that it works even if I replace REAL with FLOAT. Which sounds more reasonable. Since the original type of a and b is FLOAT. That's my explanation: an error of datatype choice.

So this problem is SOLVED
SOLUTION IS: Replace MPI::REAL with MPI::FLOAT

But now I have another problem:
The executable does not work:


>export MP_PROCS=2
> mpirun ./a.out
[:01365] *** An error occurred in MPI_Send
[:01365] *** on communicator MPI_COMM_WORLD
[:01365] *** MPI_ERR_RANK: invalid rank
[:01365] *** MPI_ERRORS_ARE_FATAL (goodbye)

What's the problem now? Maybe should I write a different post?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1