[mpich-discuss] Problems using DLL
Euan Barlow
euan.barlow at strath.ac.uk
Fri Apr 23 11:58:26 CDT 2010
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
__________________________________________
Dr Euan Barlow
Research Fellow
Department of Civil Engineering
University of Strathclyde
Glasgow
Telephone: +44 (0) 141-548-3010
E-mail: euan.barlow at strath.ac.uk
__________________________________________
The University of Strathclyde is a charitable body,
registered in Scotland, number SC015263.
More information about the mpich-discuss
mailing list