[mpich-discuss] Problems using DLL

Jayesh Krishna jayesh at mcs.anl.gov
Wed Apr 28 09:55:11 CDT 2010


Hi,
 Great ! Let us know if you need any help.

Regards,
Jayesh
----- Original Message -----
From: "Euan Barlow" <euan.barlow at strath.ac.uk>
To: "Jayesh Krishna" <jayesh at mcs.anl.gov>
Sent: Wednesday, April 28, 2010 9:31:49 AM GMT -06:00 US/Canada Central
Subject: RE: [mpich-discuss] Problems using DLL


Hi Jayesh,

That's sorted it, I had copied the dll to the solution folder instead of the debug folder... knew it would be something simple!

Cheers for your help

Euan
________________________________________
From: Jayesh Krishna [jayesh at mcs.anl.gov]
Sent: 27 April 2010 17:18
To: Euan Barlow
Cc: mpich-discuss at mcs.anl.gov
Subject: Re: [mpich-discuss] Problems using DLL

Hi,
 Try copying the library dll (TestDll.dll) to the directory containing your MPI application (D:\Euan\VisualStudio\Test_Parallel_Files\Debug) and let us know if it works for you.

(PS: I just tried compiling/running your code and it worked for me.)
Regards,
Jayesh
----- Original Message -----
From: "Euan Barlow" <euan.barlow at strath.ac.uk>
To: "Jayesh Krishna" <jayesh at mcs.anl.gov>, mpich-discuss at mcs.anl.gov
Sent: Tuesday, April 27, 2010 11:01:54 AM GMT -06:00 US/Canada Central
Subject: RE: [mpich-discuss] Problems using DLL

Hi Jayesh,

Thanks for your suggestion. I tried running it from the command line but it's still not producing any output. Once it's executed it just produces another command prompt.

I'm relatively new to this and I could be doing something stupid but I can't work out what. I would appreciate any more help you can give.

Cheers

Euan
________________________________________
From: Jayesh Krishna [jayesh at mcs.anl.gov]
Sent: 27 April 2010 15:23
To: mpich-discuss at mcs.anl.gov
Cc: Euan Barlow
Subject: Re: [mpich-discuss] Problems using DLL

Hi,
 Can you try running your code from the command line without the "-noprompt" option and let us know the results (From the command line run, "C:\Program Files\MPICH2\bin\mpiexec.exe" -n 4  D:\Euan\VisualStudio\Test_Parallel_Files\Debug\Test_Parallel_Files.exe)?

Regards,
Jayesh
----- Original Message -----
From: "Euan Barlow" <euan.barlow at strath.ac.uk>
To: mpich-discuss at mcs.anl.gov
Sent: Friday, April 23, 2010 11:58:26 AM GMT -06:00 US/Canada Central
Subject: [mpich-discuss] Problems using DLL


Hello,

I am trying to link a DLL with some code which calls MPI functions and I am having difficulties. I have created a smaller test problem which also results in the same problem.

I am using MS Visual Studio 2008. My codes are written in C++. I have downloaded the latest version of MPICH2 from the website. I am using the MPIEXEC Wrapper to execute the .exe file.

The test DLL I am using is from the VS help files. I created an empty project and added a header file called TestDll.h and a source file called TestDll.cpp. They are as follows:

// TestDll.h

namespace MathFuncs
{
    class MyMathFuncs
    {
    public:
        // Returns a + b
        static __declspec(dllexport) double Add(double a, double b);

        // Returns a - b
        static __declspec(dllexport) double Subtract(double a, double b);

        // Returns a * b
        static __declspec(dllexport) double Multiply(double a, double b);

        // Returns a / b
        // Throws DivideByZeroException if b is 0
        static __declspec(dllexport) double Divide(double a, double b);
    };
}

and

// TestDll.cpp
#include "TestDll.h"

#include <stdexcept>

using namespace std;

namespace MathFuncs
{
    double MyMathFuncs::Add(double a, double b)
    {
        return a + b;
    }

    double MyMathFuncs::Subtract(double a, double b)
    {
        return a - b;
    }

    double MyMathFuncs::Multiply(double a, double b)
    {
        return a * b;
    }

    double MyMathFuncs::Divide(double a, double b)
    {
        if (b == 0)
        {
            throw new invalid_argument("b cannot be zero!");
        }

        return a / b;
    }
}

Using the project properties I set the configuration type to .dll and built the solution. This created  .dll and .lib files. I then created a seperate project to call this library and implement some MPI functions. The source code is given below:

#include <iostream>

#include "TestDll.h"
#include "mpi.h"
using namespace std;

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

        MPI::Init ( argc, argv );
        my_id = MPI::COMM_WORLD.Get_rank ( );
        num_procs = MPI::COMM_WORLD.Get_size ( );

        cout << "Process " << my_id << " of " << num_procs << endl;



        double a = 7.4;
    int b = 99;

    cout << "a + b = " <<
        MathFuncs::MyMathFuncs::Add(a, b) << endl;
    cout << "a - b = " <<
        MathFuncs::MyMathFuncs::Subtract(a, b) << endl;
    cout << "a * b = " <<
        MathFuncs::MyMathFuncs::Multiply(a, b) << endl;
    cout << "a / b = " <<
        MathFuncs::MyMathFuncs::Divide(a, b) << endl;

        MPI::Finalize ( );

    return 0;
}

If I comment out the lines concerning MPI functions the project builds and debugs successfully and produces the expected output so I think I have linked the DLL correctly to this project. Similarly, if I comment out the rest of the lines, which use the DLL, the project builds successfully and is executed successfully from the MPIEXEC wrapper.

When I have the code as above, with no lines commented, the solution still builds successfully; however when I then try to use the MPIEXEC wrapper to execute the .exe file a command shell flashes up and disappears immediately, with no output produced. The command line in the Wrapper is

"C:\Program Files\MPICH2\bin\mpiexec.exe" -n 4  -noprompt D:\Euan\VisualStudio\Test_Parallel_Files\Debug\Test_Parallel_Files.exe

I would be very grateful if anyone can provide advice as to what I can do to solve this problem.

Regards

Euan



More information about the mpich-discuss mailing list