使用NVCC对“name”进行未定义的引用

时间:2012-10-16 16:03:47

标签: c++ gcc cuda nvcc

我正在尝试以非标准的方式编译gpgmg CUDA模拟,因为我没有对我试图运行它的机器的root访问权。

此模拟广泛使用HDF5库(http://www.hdfgroup.org/HDF5/)。当我在没有root访问权限的机器上运行它时,我无法安装HDF5。因此,我下载了文件并将其粘贴在include目录中。我使用以下命令使用NVCC进行编译(是的,我知道这应该是makefile格式)。

nvcc main.cpp CAnnihilationProblem.cpp CCompartment.cpp CDiffusionModel.cpp CFirstOrderReaction.cpp CFisherProblem.cpp CLocalizedAnnihilationProblem.cpp CModel.cpp CReaction.cpp CReactionProblem.cpp CSecondOrderReaction.cpp CSemiInfiniteSlabProblem.cpp CSimpleDiffusionProblem.cpp CSimpleInhomogeneousDiffusionProblem.cpp CSimpleLocalizedFirstOrderReaction.cpp CSimpleLocalizedSecondOrderReaction.cpp CSimpleLocalizedZerothOrderReaction.cpp CZeroOrderReaction.cpp -lgsl -I ../include 

这编译很好(如果我只使用-c标志),但当我来链接它时,我得到以下错误:

/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../lib64/crt1.o: In function `_start':
/usr/src/packages/BUILD/glibc-2.11.1/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
/tmp/tmpxft_0000061e_00000000-2_CCompartment.o: In function `gpgmp::CCompartment::saveHdf5(int)':
CCompartment.cpp:(.text+0xbb): undefined reference to `H5Screate_simple'
CCompartment.cpp:(.text+0xc3): undefined reference to `H5open'
CCompartment.cpp:(.text+0xc9): undefined reference to `H5T_NATIVE_INT_g'
CCompartment.cpp:(.text+0x106): undefined reference to `H5Dcreate2'
CCompartment.cpp:(.text+0x13f): undefined reference to `H5open'
CCompartment.cpp:(.text+0x145): undefined reference to `H5T_NATIVE_INT_g'
CCompartment.cpp:(.text+0x164): undefined reference to `H5Dwrite'
CCompartment.cpp:(.text+0x16f): undefined reference to `H5Dclose'
CCompartment.cpp:(.text+0x17a): undefined reference to `H5Sclose'
/tmp/tmpxft_0000061e_00000000-3_CDiffusionModel.o: In function `gpgmp::CDiffusionModel::closeOutputFile(gpgmp::DiffusionModelRuntimeInformation const*)':
CDiffusionModel.cpp:(.text+0x336): undefined reference to `H5Gclose'
CDiffusionModel.cpp:(.text+0x364): undefined reference to `H5Fclose'
/tmp/tmpxft_0000061e_00000000-3_CDiffusionModel.o: In function `gpgmp::CDiffusionModel::prepareOutputFile(gpgmp::DiffusionModelRuntimeInformation*)':
CDiffusionModel.cpp:(.text+0x4bc): undefined reference to `H5check_version'
CDiffusionModel.cpp:(.text+0x4e7): undefined reference to `H5Fopen'
CDiffusionModel.cpp:(.text+0x646): undefined reference to `H5Gcreate2'
CDiffusionModel.cpp:(.text+0x6e8): undefined reference to `H5Gclose'
CDiffusionModel.cpp:(.text+0x719): undefined reference to `H5Fclose'
/tmp/tmpxft_0000061e_00000000-3_CDiffusionModel.o: In function `gpgmp::CDiffusionModel::createOutputFile(gpgmp::DiffusionModelRuntimeInformation*)':
CDiffusionModel.cpp:(.text+0x8f3): undefined reference to `H5check_version'
CDiffusionModel.cpp:(.text+0x923): undefined reference to `H5Fcreate'
CDiffusionModel.cpp:(.text+0x99d): undefined reference to `H5Gcreate2'
CDiffusionModel.cpp:(.text+0x9bb): undefined reference to `H5Screate_simple'
CDiffusionModel.cpp:(.text+0x9c3): undefined reference to `H5open'
CDiffusionModel.cpp:(.text+0x9c9): undefined reference to `H5T_NATIVE_INT_g'
CDiffusionModel.cpp:(.text+0x9ec): undefined reference to `H5Dcreate2'
CDiffusionModel.cpp:(.text+0xa06): undefined reference to `H5open'
CDiffusionModel.cpp:(.text+0xa0c): undefined reference to `H5T_NATIVE_INT_g'
CDiffusionModel.cpp:(.text+0xa2b): undefined reference to `H5Dwrite'
CDiffusionModel.cpp:(.text+0xa36): undefined reference to `H5Dclose'
CDiffusionModel.cpp:(.text+0xa41): undefined reference to `H5Sclose'
CDiffusionModel.cpp:(.text+0xad0): undefined reference to `H5open'
CDiffusionModel.cpp:(.text+0xad6): undefined reference to `H5T_C_S1_g'
CDiffusionModel.cpp:(.text+0xadb): undefined reference to `H5Tcopy'
CDiffusionModel.cpp:(.text+0xaed): undefined reference to `H5Tset_size'
CDiffusionModel.cpp:(.text+0xb03): undefined reference to `H5Screate_simple'
CDiffusionModel.cpp:(.text+0xb2c): undefined reference to `H5Dcreate2'
CDiffusionModel.cpp:(.text+0xb51): undefined reference to `H5Dwrite'
CDiffusionModel.cpp:(.text+0xb5c): undefined reference to `H5Dclose'
CDiffusionModel.cpp:(.text+0xb67): undefined reference to `H5Sclose'
CDiffusionModel.cpp:(.text+0xb8e): undefined reference to `H5Screate_simple'
CDiffusionModel.cpp:(.text+0xb96): undefined reference to `H5open'
CDiffusionModel.cpp:(.text+0xb9c): undefined reference to `H5T_NATIVE_INT_g'
CDiffusionModel.cpp:(.text+0xbbf): undefined reference to `H5Dcreate2'
CDiffusionModel.cpp:(.text+0xbd9): undefined reference to `H5open'
CDiffusionModel.cpp:(.text+0xbdf): undefined reference to `H5T_NATIVE_INT_g'
CDiffusionModel.cpp:(.text+0xbfe): undefined reference to `H5Dwrite'
CDiffusionModel.cpp:(.text+0xc09): undefined reference to `H5Dclose'
CDiffusionModel.cpp:(.text+0xc14): undefined reference to `H5Sclose'
CDiffusionModel.cpp:(.text+0xc34): undefined reference to `H5Gcreate2'
CDiffusionModel.cpp:(.text+0xcb4): undefined reference to `H5Gclose'
CDiffusionModel.cpp:(.text+0xcbf): undefined reference to `H5Gclose'
/tmp/tmpxft_0000061e_00000000-3_CDiffusionModel.o: In function `gpgmp::CDiffusionModel::openOutputFile(gpgmp::DiffusionModelRuntimeInformation*)':
CDiffusionModel.cpp:(.text+0xe1d): undefined reference to `H5check_version'
CDiffusionModel.cpp:(.text+0xe48): undefined reference to `H5Fopen'
CDiffusionModel.cpp:(.text+0xf9c): undefined reference to `H5Gopen2'
/tmp/tmpxft_0000061e_00000000-3_CDiffusionModel.o: In function `gpgmp::CDiffusionModel::writeAllSpecies(float, gpgmp::DiffusionModelRuntimeInformation*)':
CDiffusionModel.cpp:(.text+0x141b): undefined reference to `H5Gcreate2'
CDiffusionModel.cpp:(.text+0x147f): undefined reference to `H5Screate_simple'
CDiffusionModel.cpp:(.text+0x1487): undefined reference to `H5open'
CDiffusionModel.cpp:(.text+0x148d): undefined reference to `H5T_NATIVE_FLOAT_g'
CDiffusionModel.cpp:(.text+0x14b0): undefined reference to `H5Dcreate2'
CDiffusionModel.cpp:(.text+0x14b8): undefined reference to `H5open'
CDiffusionModel.cpp:(.text+0x14be): undefined reference to `H5T_NATIVE_FLOAT_g'
CDiffusionModel.cpp:(.text+0x14e0): undefined reference to `H5Dwrite'
CDiffusionModel.cpp:(.text+0x14eb): undefined reference to `H5Dclose'
CDiffusionModel.cpp:(.text+0x14f6): undefined reference to `H5Sclose'
CDiffusionModel.cpp:(.text+0x15c6): undefined reference to `H5Screate_simple'
CDiffusionModel.cpp:(.text+0x15ce): undefined reference to `H5open'
CDiffusionModel.cpp:(.text+0x15d4): undefined reference to `H5T_NATIVE_INT_g'
CDiffusionModel.cpp:(.text+0x161e): undefined reference to `H5Dcreate2'
CDiffusionModel.cpp:(.text+0x165e): undefined reference to `H5open'
CDiffusionModel.cpp:(.text+0x1664): undefined reference to `H5T_NATIVE_INT_g'
CDiffusionModel.cpp:(.text+0x1683): undefined reference to `H5Dwrite'
CDiffusionModel.cpp:(.text+0x168e): undefined reference to `H5Dclose'
CDiffusionModel.cpp:(.text+0x1699): undefined reference to `H5Sclose'
CDiffusionModel.cpp:(.text+0x16bb): undefined reference to `H5Gclose'
/tmp/tmpxft_0000061e_00000000-3_CDiffusionModel.o: In function `gpgmp::CDiffusionModel::runSomeGmps(void*)':
CDiffusionModel.cpp:(.text+0x17ff): undefined reference to `chooseDevice(int)'
CDiffusionModel.cpp:(.text+0x1883): undefined reference to `gpgmp::CDiffusionModel::cudaRunGMPInhomogeneous(gpgmp::DiffusionModelRuntimeInformation*)'
CDiffusionModel.cpp:(.text+0x1892): undefined reference to `gpgmp::CDiffusionModel::cudaRunGMP(gpgmp::DiffusionModelRuntimeInformation*)'
/tmp/tmpxft_0000061e_00000000-3_CDiffusionModel.o: In function `gpgmp::CDiffusionModel::runMultipleGmps(int, int, float, float, float, int, bool, void*)':
CDiffusionModel.cpp:(.text+0x2b4d): undefined reference to `queryCudaDevices()'
/tmp/tmpxft_0000061e_00000000-7_CModel.o: In function `gpgmp::CModel::gillespie(int, bool)':
CModel.cpp:(.text+0x8d9): undefined reference to `gpgmp::cudaRunGillespie(float*, int*, float*, float*, gpgmp::RateLaw*, int, int, int)'
collect2: ld returned 1 exit status

我的第一个想法是main()没有被定义,但确实如此。这是main.cpp:

#include "CModel.h"
#include "CDiffusionModel.h"
#include "CAnnihilationProblem.h"
#include "CSemiInfiniteSlabProblem.h"
#include "CSimpleDiffusionProblem.h"
#include "CSimpleInhomogeneousDiffusionProblem.h"
#include "CLocalizedAnnihilationProblem.h"
#include "CFisherProblem.h"
#include "CReactionProblem.h"
#include "definitions.h"
#include "CSecondOrderReaction.h"

#include <getopt.h>
#include <cstdio>
#include <iostream>

using namespace std;

int chooseCudaDevice(int device);

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

    // parameters
    int dx=32, dy=32;
    int numRuns=10;
    int numSteps=500000;
    float time=100.;
    REAL length=40.;

    //opterr = 0;
    int c;

    int numCudaDevices=-1;
    int problem=0;
    float p0 = 0.1;
    float dt = 0.1;

    gpgmp::OutputFormat outputFormat = gpgmp::OUTPUT_HDF5;

    while ((c = getopt (argc, argv, "x:y:t:l:n:r:d:p:w:o:f:")) != -1)
        switch (c)
        {
        case 'x':
            dx = atoi(optarg);
            break;
        case 'y':
            dy = atoi(optarg);
            break;
        case 't':
            time = atof(optarg);
            break;
        case 'l':
            length = atof(optarg);
            break;
        case 'n':
            numSteps = atoi(optarg);
            break;
        case 'r':
            numRuns = atoi(optarg);
            break;
        case 'd':
            // number of devices to run on
            numCudaDevices = atoi(optarg);
            break;
        case 'p':
            problem = atoi(optarg);
            break;
        case 'o':
            dt = atof(optarg);
            break;
        case 'w':
            p0 = atof(optarg);
            break;
        case 'f':
            switch(atoi(optarg)) {
            case 0:
                cout <<"Setting output format to ASCII.\n";
                outputFormat = gpgmp::OUTPUT_ASCII;
                break;
            case 1:
                cout <<"Setting output format to HDF5.\n";
                outputFormat = gpgmp::OUTPUT_HDF5;
                break;
            }
            break;
            case '?':
                if (optopt == 'x' || optopt =='y' || optopt == 't'
                        || optopt =='l' || optopt == 'n' || optopt=='r' || optopt=='d'
                                || optopt=='p' || optopt == 'w')
                    fprintf (stderr, "Option -%c requires an argument.\n", optopt);
                else if (isprint (optopt))
                    fprintf (stderr, "Unknown option `-%c'.\n", optopt);
                else
                    fprintf (stderr,
                            "Unknown option character `\\x%x'.\n",
                            optopt);
                return 1;
            default:
                abort ();
        }


    int index=optind;

    cout <<"Welcome to gmp.\n";
    cout <<"System dimensions: length="<<length
            <<", dx="<<dx<<", dy="<<dy<<"\n";
    cout <<"Runtime configuration: time="<<time
            <<", number of Runs="<<numRuns
            <<", number of Steps="<<numSteps
            <<", output dt="<<dt
            <<", problem nr="<<problem
            <<"\n";


    if (problem == 0) {
        // A plus B reaction model
        float diffusionConstant;
        float k1;
        float k2;
        float k3;
        float k4;
        if (index == argc-5) {
            diffusionConstant=atof(argv[index++]);
            k1=atof(argv[index++]);
            k2=atof(argv[index++]);
            k3=atof(argv[index++]);
            k4=atof(argv[index++]);
        } else if (index==argc) {
            cout <<"No parameters given, using default.\n";
            length=100.;
            dx=128;
            dy=128;
            p0=0.1;
            time=500.;
            k1=1e-3;
            k2=1e-2;
            k3=1.2;
            k4=1.;
            diffusionConstant=0.;
        } else {
            cout <<"Mismatching parameters. Usage:\n";
            cout <<"gpgmp -p 3 [diffusionConstant k1 k2 k3 k4].\n";
            exit(1);
        }
        cout <<"Setting up A plus B reaction problem with diffusion Constant :"
                <<diffusionConstant<<"\n";
        cout <<"k1 = "<<k1<<", k2 = "<<k2<<", k3 = "<<k3<<", k4 = "<<k4<<"\n";
        gpgmp::CReactionProblem reaction(length, dx, dy, diffusionConstant, k1, k2, k3, k4);
        reaction.setOutputFormat(outputFormat);
        reaction.runMultipleGmps(numRuns, numSteps, time, p0, dt);
    } else if (problem == 1) {
        // FISHER PROBLEM
        float baseConcentration = atof(argv[index++]);
        cout <<"Setting up Fisher Problem with concentration "<<baseConcentration<<".\n";

        gpgmp::CFisherProblem fisher(length, dx, dy, baseConcentration);
        fisher.setOutputFormat(gpgmp::OUTPUT_HDF5);
        fisher.runMultipleGmps(numRuns, numSteps, time, p0, dt);
    } else if (problem == 2) {
        // SIMPLE DIFFUSION
        float diffusionConstant;
        int numMolecules;

        if (index == argc-2) {
            diffusionConstant=atof(argv[index++]);
            numMolecules = atoi(argv[index++]);
        } else if (index==argc) {
            cout <<"No parameters given, using default.\n";
            length=100.;
            dx=128;
            dy=128;
            p0=0.1;
            dt = 5.;
            time=20.;
            diffusionConstant=1.;
            numMolecules = 1e5;
        } else {
            cout <<"Mismatching parameters. Usage:\n";
            cout <<"gpgmp -p 2 [diffusionConstant numMolecules].\n";
            exit(1);
        }

        cout <<"Setting up simple diffusion problem with diffusion Constant :"<<diffusionConstant
                <<", nMol:"<<numMolecules<<" \n";

        gpgmp::CSimpleDiffusionProblem diffusion(
                length, dx, dy, diffusionConstant, numMolecules);
        diffusion.setOutputFormat(gpgmp::OUTPUT_HDF5);
        diffusion.runMultipleGmps(numRuns, numSteps, time, p0, dt,numCudaDevices);
    } else if (problem ==3) {
        // LOCALIZED A+B ANNIHILATION
        cout <<"Setting up localized A plus B reaction problem.\n";
        float diffusionConstant;
        float k1, k2, k3, k4;
        float xminA, xmaxA,xminB, xmaxB;

        if (index == argc-9) {
            diffusionConstant=atof(argv[index++]);
            k1=atof(argv[index++]);
            k2=atof(argv[index++]);
            k3=atof(argv[index++]);
            k4=atof(argv[index++]);
            xminA=atof(argv[index++]);
            xmaxA=atof(argv[index++]);
            xminB=atof(argv[index++]);
            xmaxB=atof(argv[index++]);
        } else if (index==argc) {
            cout <<"No parameters given, using default.\n";
            length=1000.;
            dx=32;
            dy=32;
            p0=0.1;
            time=1800.;
            k1=9.4096e+09;
            k2=9.4096e+10;
            k3=1.27529e-13;
            k4=1.06274e-13;
            diffusionConstant=100.;
            xminA = 0.;
            xmaxA = 900.;
            xminB = 400.;
            xmaxB = 1000.;
        } else {
            cout <<"Mismatching parameters. Usage:\n";
            cout <<"gpgmp -p 3 [diffusionConstant k1 k2 k3 k4 xminA xmaxA xminB xmaxB].\n";
            exit(1);
        }
        cout <<"Parameters : diffusion Constant :"<<diffusionConstant<<"\n";
        cout <<"k1 = "<<k1<<", k2 = "<<k2<<", k3 = "<<k3<<", k4 = "<<k4<<"\n";
        cout <<"xminA = "<<xminA<<", xmaxA = "<<xmaxA<<", xminB = "<<xminB<<", xmaxB = "<<xmaxB<<"\n";

        gpgmp::CLocalizedAnnihilationProblem problem(length, dx, dy,
                diffusionConstant, k1, k2, k3, k4,
                xminA, xmaxA, xminB, xmaxB);
        problem.runMultipleGmps(numRuns, numSteps, time, p0, dt);
    } else if (problem == 4) {
        // SEMI-INFINITE SLAB problem
        cout <<"Setting up semi-infinite slab problem.\n";
        float diffusionConstant;
        float sourceNumber;

        if (index == argc-2) {
            diffusionConstant=atof(argv[index++]);
            sourceNumber=atof(argv[index++]);
        } else if (index==argc) {
            cout <<"No parameters given, using default.\n";
            length=40.;
            dx=64;
            dy=64;
            p0=0.1;
            time=1000;
            diffusionConstant=1.;
            sourceNumber = 10.;
            dt=500.;
        } else {
            cout <<"Mismatching parameters. Usage:\n";
            cout <<"gpgmp -p 4 [diffusionConstant sourceNumber].\n";
            exit(1);
        }
        cout <<"Setting up semi-infinite slab problem.\n";
        cout <<"Source number is:"<<sourceNumber<<", diffusion Constant:"
                <<diffusionConstant<<"\n";
        gpgmp::CSemiInfiniteSlabProblem
        slabModel(length, dx, dy, sourceNumber, diffusionConstant);
        slabModel.setOutputFormat(gpgmp::OUTPUT_HDF5);
        slabModel.runMultipleGmps(numRuns, numSteps, time, p0, dt);
    } else if (problem == 5) {
        // Sets up the A+B annihilation model
        REAL length = 12.8; // In micrometer
        REAL nx = 64; // Number of cells in each direction
        gpgmp::CDiffusionModel testModel(length, nx, nx);

        // add species to model
        REAL diffusivity = 1; // In micrometer^2 s^-1
        testModel.addDiffusionSpecies("A", diffusivity);
        testModel.addDiffusionSpecies("B", diffusivity);
        testModel.addDiffusionSpecies("C", diffusivity);


        // create "source" and "world" compartments
        gpgmp::CCompartment comp1("Source", 32, 32, 32, 32);
        gpgmp::CCompartment comp2("World",0, 0, 63, 63);

        // add species to compartment
        comp1.setInitialAmount("A", 1000, gpgmp::DIST_HOMOGENEOUS);
        comp2.setInitialAmount("B", 1000, gpgmp::DIST_RANDOM);

        // and add it to the main model
        testModel.addCompartment(0, comp1);
        testModel.addCompartment(1, comp2);

        // add the annihilation reaction
        // A+B -> C
        REAL reactionRate = 1e8; // Reaction rate in M^-1 s^-1

        // set the reaction products
        std::map<std::string, int> aplusbAnnihilationMap;
        aplusbAnnihilationMap["C"]=1;

        // and create the reaction
        gpgmp::CSecondOrderReaction *aplusbAnnihilation =
                new gpgmp::CSecondOrderReaction("A plus B annihilation",
                testModel.getSecondOrderReactionRate(reactionRate),
                "A", "B", aplusbAnnihilationMap);
        testModel.addReaction(aplusbAnnihilation);

        // set output format
        testModel.setOutputFormat(gpgmp::OUTPUT_HDF5);

        // run the GMP to test the output
        int nRuns = 100; // Number of runs
        int nSteps = 10000; // Max number of steps
        REAL simTime = 5.; // Max simulation time
        REAL p = 0.1; // Probability for a particle to stay
        REAL dumpTime = 1.; // Interval of output dumps
        testModel.runMultipleGmps(nRuns, nSteps, simTime, p, dumpTime);

    } else if (problem==6) {
        // 2D A+B annihilation problem
        std::cout <<"Setting up 2D annihilation problem.";

        // default parameters
        REAL diffusionConstant = 1.;
        REAL rate;
        int numMolecules;

        // check if more parameters are given - if not take defaults
        if (index == argc-3) {
            diffusionConstant=atof(argv[index++]);
            rate=atof(argv[index++]);
            numMolecules = atoi(argv[index++]);
        } else if (index == argc) {
            // use defaults
            cout <<"No parameters given ... using defaults.\n";
            length=12.8;
            dx=64;
            dy=64;
            p0=0.1;
            time=4.;
            rate = 1e8;
            numMolecules = 100000.;
        } else {
            cout <<"Mismatching parameters. Usage:\n";
            cout <<"gpgmp -p 6 diffusionConstant rate numMolecules.\n";
            exit(1);
        }
        std::cout <<"Annihilation rate is:"<<rate<<", diffusion Constant:"
                <<diffusionConstant<<", number of Molecules:"
                <<numMolecules<<".\n";

        gpgmp::CAnnihilationProblem model(length, dx, dy, numMolecules,
                diffusionConstant, rate);
        model.setOutputFormat(outputFormat);
        model.runMultipleGmps(numRuns, numSteps, time, p0, dt,numCudaDevices);
    } else if (problem == 7) {
        // SIMPLE INHOMOGENEOUS DIFFUSION
        float diffusionConstant=atof(argv[index++]);
        int numMolecules = atoi(argv[index++]);
        int testModel = atoi(argv[index++]);

        gpgmp::InhomogeneousDiffusionParameters kernelParams;

        // set dimensionality
        kernelParams.dimensionality = 1;

        cout <<"Setting up simple inhomogeneous diffusion problem with diffusion Constant :"
                <<diffusionConstant <<", nMol:"<<numMolecules<<".\n";
        cout <<"Test model is ";
        REAL u0, a;

        gpgmp::CSimpleInhomogeneousDiffusionProblem *diffusion;

        switch (testModel) {
        case 0:
            cout <<"constant diffusivity.\n";
            kernelParams.diffusionType =
                    gpgmp::InhomogeneousDiffusionParameters::DT_HOMOGENEOUS;
            diffusion = new gpgmp::CSimpleInhomogeneousDiffusionProblem(
                    length, dx, dy, diffusionConstant, numMolecules, true);
            break;
        case 1:
            u0 = atof(argv[index++]);
            cout <<"population pressure model with u0="<<u0<<".\n";
            kernelParams.diffusionType =
                    gpgmp::InhomogeneousDiffusionParameters::DT_LOCAL_AVERAGE;
            kernelParams.testModelType =
                    gpgmp::InhomogeneousDiffusionParameters::TM_POPULATION_PRESSURE;
            kernelParams.u0 = u0;
            diffusion = new gpgmp::CSimpleInhomogeneousDiffusionProblem(
                    length, dx, dy, diffusionConstant, numMolecules, false);
            break;
        case 2:
            a = atof(argv[index++]);
            cout <<"contact inhibition model with A="<<a<<".\n";
            kernelParams.diffusionType =
                    gpgmp::InhomogeneousDiffusionParameters::DT_LOCAL_AVERAGE;
            kernelParams.testModelType =
                    gpgmp::InhomogeneousDiffusionParameters::TM_CONTACT_INHIBITION;
            kernelParams.a = a;
            diffusion = new gpgmp::CSimpleInhomogeneousDiffusionProblem(
                    length, dx, dy, diffusionConstant, numMolecules, false);
            break;
        }

        diffusion->runMultipleGmps(numRuns, numSteps, time, p0, dt,numCudaDevices,
                true, (void *) &kernelParams);
    } else if (problem == 8) {
        // Slit Problem
        REAL length = 1200.;
        gpgmp::CDiffusionModel testModel(length, dx, dy);

        // create new Compartment
        gpgmp::CCompartment comp1("Explant", dx/2-1, dy/2-1, dx/2, dy/2);

        // add species to compartment
        comp1.setInitialAmount("Cells", 20398, gpgmp::DIST_HOMOGENEOUS);

        // and add it to the main model
        testModel.addCompartment(0, comp1);

        // add species
        testModel.addDiffusionSpecies("Cells", 0.56);

        // create the kernel parameters structure
        gpgmp::InhomogeneousDiffusionParameters kernelParams;
        kernelParams.dimensionality = 2;
        kernelParams.testModelType =
                gpgmp::InhomogeneousDiffusionParameters::TM_SLIT;
        // slit parameters
        kernelParams.lambda = 0.01;
        kernelParams.beta = 20;
        kernelParams.length = length;
        REAL subVolume = length/dx*length/dx;
        kernelParams.a = 0.02*subVolume;
        kernelParams.ta = 24.*3600.;
        kernelParams.xi = 1e4/3600.;

        // set diffusion type
        int diffType = atoi(argv[index++]);

        switch(diffType) {
        case 0:
            kernelParams.diffusionType =
                    gpgmp::InhomogeneousDiffusionParameters::DT_STRICTLY_LOCAL;
            break;
        case 1:
            kernelParams.diffusionType =
                    gpgmp::InhomogeneousDiffusionParameters::DT_LOCAL_AVERAGE;
            break;
        case 2:
            kernelParams.diffusionType =
                    gpgmp::InhomogeneousDiffusionParameters::DT_NEIGHBOUR_BASED;
            break;
        case 3:
            kernelParams.diffusionType =
                    gpgmp::InhomogeneousDiffusionParameters::DT_GRADIENT_BASED;
            break;
        }

        // run the GMP to test the output
        testModel.runMultipleGmps(numRuns, numSteps, time, p0, dt, numCudaDevices,
                true, (void *) &kernelParams);
    }
}

由于这是经过同行评审的代码,我假设错误与我链接它的方式有关....

如何才能正确链接?

1 个答案:

答案 0 :(得分:1)

您必须显式链接代码中的库依赖项。这里的错误是由于没有链接合适的HDF5库而导致不满意的依赖性。如果您在相对于工作目录的路径../include中安装了缺少的库,那么就像这样:

nvcc -I ../include main.cpp CAnnihilationProblem.cpp CCompartment.cpp CDiffusionModel.cpp \
      CFirstOrderReaction.cpp CFisherProblem.cpp CLocalizedAnnihilationProblem.cpp \ 
      CModel.cpp CReaction.cpp CReactionProblem.cpp CSecondOrderReaction.cpp 
      CSemiInfiniteSlabProblem.cpp CSimpleDiffusionProblem.cpp \
      CSimpleInhomogeneousDiffusionProblem.cpp \
      CSimpleLocalizedFirstOrderReaction.cpp CSimpleLocalizedSecondOrderReaction.cpp  \
      CSimpleLocalizedZerothOrderReaction.cpp CZeroOrderReaction.cpp \
      -L../include -lgsl -lhdf5

应该允许代码正确链接。

[此答案汇总自评论作为社区维基条目,以便将问题从未答复的列表中删除]。