Hello, I have such a problem. Using the capabilities of MPI, implement a parallel matrix multiplication algorithm. Writes an error:

ссылка на неразрешенный внешний символ _MPI_Init в функции "void __cdecl MultiplyMatrix(float *,float *,float *,int)" (?MultiplyMatrix@@YAXPAM00H@Z) 

code:

 #include <iostream> #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <ctime> #include <mpi.h> #define N 100 using namespace std; float *CreateMatrix( int n) { float *matr = new float [n*n]; return matr; } void FillMatrix(float *matrix, int n) { for (int i=0; i<n; i++) for (int j=0; j<n; j++) *(matrix+i*n+j) = rand()%10; } void MultiplyMatrix(float *mA,float *mB, float *mC,int n) { int rank; int size; int argc; char **argv; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPI_Bcast(&n,1,MPI_FLOAT,0,MPI_COMM_WORLD); int i; int j; float matrix; //MPI_Comm_rank(MPI_COMM_WORLD, &rank); for (i=0; i<n; i++) {if (rank!=0) { for (j=0; j<n; j++) { float s = 0; for (int k=0; k<n; k++) { s +=*(mA+i*n+k) * *(mB+k*n+j); //s=s%10; } *(mC+i*n+j) = s; } } } // MPI_Reduce(&mC+i*n+j,&matrix,1,MPI_FLOAT,MPI_SUM,0,MPI_COMM_WORLD); MPI_Finalize(); } void PrintMatrix(float *matrix,char *name, int n) { cout<<"Matrix\t"; cout<<name; cout<<"\n"; for (int i=0; i<n; i++) { for (int j=0; j<n; j++) { cout<<*(matrix+i*n+j) <<' '; } cout<<endl; } } int main(int argc, char *argv[]) { int SIZE = 20; int n; float *mA; float *mB; float *mC; double t1,t2,t3,t4; double total_1, total_2,total_3; printf("\n ===SIZE=========LAB1============MPI=====\n"); for(int j=0; j<8; j++) float start_time; float total_time; float search_time; float end_time; for(int j=0; j<8; j++) { mA = CreateMatrix(SIZE); mB = CreateMatrix(SIZE); mC = CreateMatrix(SIZE); FillMatrix(mA, SIZE); FillMatrix(mB, SIZE); total_1 = total_2=0; for(int i=0;i<N;i++) { t1 = clock(); MultiplyMatrix(mA,mB,mC,SIZE); t2 = clock(); MultiplyMatrix(mA,mB,mC,SIZE); t3 = clock(); total_1 += (t2-t1); total_2 += (t3-t2); } printf("\n %dx%d\t%.4lf \t%.4lf",SIZE,SIZE,total_1/N,total_2/N); SIZE += 30; delete mA; delete mB; delete mC; } printf("\n\n =================================\n"); printf("\n\n"); getch(); //MPI_Barrier(MPI_COMM_WORLD); return 0; } 

Help, please. What is the error?

  • 2
    Your library does not connect. For linux, look at the compiler options here , and for Windows (only by getch guessed it) here (in general, getch OS, compiler, etc.). - avp
  • one
    @avp: judging by #include <conio.h> , this is not Windows, but even DOS. Visual Studio C ++, starting from somewhere in 2010, already fully supports the standards. - VladD
  • He writes the following error: 1> lab_5.obj: error LNK2019: link to unresolved external symbol _MPI_Init in the function "void __cdecl MultiplyMatrix (float *, float *, float *, int)" (? MultiplyMatrix @@ YAXPAM00H @ Z) - Oleg74

1 answer 1

Read the documentation for your MPI implementation. On Linux, everything is compiled with the mpicc command (instead of cc) or mpicxx (for c ++). In Windows-DOS, it is also possible, but without knowing what and how you have delivered it is definitely impossible to answer.