ZioFrancis
ZioFrancis

Reputation: 39

mpi compiling warning implicit declaration

today I install mpi on mi mac 10.9 with home-brew mpicc works with a simlpe hello world program, but if I try somethings like this

#include <mpi.h>
#include <string.h>
#include <stdio.h>
#define max 1000

int main(int argv, char *argc[]){


    int myrank,nProc,tag,j;
    char buff [max];
    MPI_Status status;
    tag=0;
    MPI_Init(&argv,&argc);
    MPI_Comm_Rank(MPI_COMM_WORLD,&myrank);
    MPI_Comm_Size(MPI_COMM_WORLD,&nProc);

    if(myrank==0){
    for(j =1 ; j<nProc;j++){
    MPI_Recv(&buff,max,MPI_CHAR,j,tag,MPI_COMM_WORLD,&status);
    printf("Il processo %d dice di chiamarsi %s\n",j,buff);
    }

                }
                else{
                switch (myrank){
                case 1 :
                 MPI_Send("Franco",max,MPI_CHAR,j,tag,MPI_COMM_WORLD);
                 break;
                 case 2 :
                 MPI_Send("Mena",max,MPI_CHAR,j,tag,MPI_COMM_WORLD);
                 break;
                 case 3 :
                 MPI_Send("Nino",max,MPI_CHAR,j,tag,MPI_COMM_WORLD);
                 break;
                                }
                    }
    printf("Ciao da %d \n",myrank);
    MPI_Finalize();
    return(0);
                               }

and i try compiling it whit the following row:

mpicc -o filename filename.c

it give me this warnings and not built .

nucciampi.c:15:3: warning: implicit declaration of function 'MPI_Comm_Rank' is
      invalid in C99 [-Wimplicit-function-declaration]
                MPI_Comm_Rank(MPI_COMM_WORLD,&myrank);
                ^
nucciampi.c:16:3: warning: implicit declaration of function 'MPI_Comm_Size' is
      invalid in C99 [-Wimplicit-function-declaration]
                MPI_Comm_Size(MPI_COMM_WORLD,&nProc);
                ^
2 warnings generated.
Undefined symbols for architecture x86_64:
  "_MPI_Comm_Rank", referenced from:
      _main in nucciampi-zsehoq.o
  "_MPI_Comm_Size", referenced from:
      _main in nucciampi-zsehoq.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

please help me to solve this issues!!!

Upvotes: 1

Views: 4214

Answers (2)

Hristo Iliev
Hristo Iliev

Reputation: 74355

There is a well-defined naming convention for all routines and constants in MPI and it is described in §2.2 of the MPI specification:

In C, all routines associated with a particular type of MPI object should be of the form MPI_Class_action_subset or, if no subset exists, of the form MPI_Class_action. In Fortran, all routines associated with a particular type of MPI object should be of the form MPI_CLASS_ACTION_SUBSET or, if no subset exists, of the form MPI_CLASS_ACTION. For C and Fortran we use the C++ terminology to define the Class. In C++, the routine is a method on Class and is named MPI::Class::Action_subset. If the routine is associated with a certain class, but does not make sense as an object method, it is a static member function of the class.

Note that unlike in Fortran, symbol names in C are case sensitive.

Upvotes: 2

Wesley Bland
Wesley Bland

Reputation: 9062

MPI_Comm_Rank -> MPI_Comm_rank

MPI_Comm_Size -> MPI_Comm_size

Upvotes: 4

Related Questions