mpich2 visual studio 2013 linker error

mpich2 visual studio 2013 linker error

本文关键字:linker error 2013 studio visual mpich2      更新时间:2023-10-16

我想以c 方式使用mpi,所以我有mpich2的cxxpi.cxx代码:

#include "mpi.h"
#include <iostream>
#include <math.h>
using namespace std;
double f(double);
double f(double a) {
    return (4.0 / (1.0 + a*a));
}
int main(int argc, char **argv) {
    int n, myid, numprocs, i;
    double PI25DT = 3.141592653589793238462643;
    double mypi, pi, h, sum, x;
    double startwtime = 0.0, endwtime;
    int  namelen;
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    MPI::Init(argc, argv);
    numprocs = MPI::COMM_WORLD.Get_size();
    myid = MPI::COMM_WORLD.Get_rank();
    MPI::Get_processor_name(processor_name, namelen);
    cout << "Process " << myid << " of " << numprocs << " is on " <<
        processor_name << endl;
    n = 10000;          /* default # of rectangles */
    if (myid == 0)
        startwtime = MPI::Wtime();
    MPI::COMM_WORLD.Bcast(&n, 1, MPI_INT, 0);
    h = 1.0 / (double) n;
    sum = 0.0;
    /* A slightly better approach starts from large i and works back */
    for (i = myid + 1; i <= n; i += numprocs) {
        x = h * ((double) i - 0.5);
        sum += f(x);
    }
    mypi = h * sum;
    MPI::COMM_WORLD.Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0);
    if (myid == 0) {
        endwtime = MPI::Wtime();
        cout << "pi is approximately " << pi << " Error is " <<
            fabs(pi - PI25DT) << endl;
        cout << "wall clock time = " << endwtime - startwtime << endl;
    }
    MPI::Finalize();
    return 0;
}

我设置了VS2013项目的属性:

  1. 属性> vc 目录> include目录>(添加路径)" c: program Files mpich2 include"
  2. 属性> VC 目录>库目录>(添加路径)" C: Program Files MPICH2 LIB"
  3. 属性>链接>输入>其他依赖关系>(添加lib)" mpi.lib"
  4. properties>平台>(设置为)活动(x64)

我有未解决的参考链接器错误。具有相同属性的CPI.C代码毫无问题。我认为问题是在LIBS中需要的,但是我试图找到它们的组合,但并不能解决问题。mpich2具有这样的lib:cxx.lib,fmpich2.lib,fmpich2g.lib,irlog2rlog.lib,mpe.lib,mpi.lib,rlog.lib,traceinput.lib。如何使程序正确工作?

您需要添加另外一个额外的依赖项-cxx.lib

此库包含C 的所有必要绑定。

您可以查看mpich2/示例/cxxpi.vcproj,以发现需要链接此库。