I have a simple MPI application that is used to pass values from process 0 to other processes upon entering the desired value but it is triggering a breakpoint on "else".
What am I missing?
#include "stdafx.h"
#include "mpi.h"
#include "stdio.h"
#include "stdlib.h"
int main(int argc, char* argv[])
{
int rank;
int value;
int size;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
do
{
if (rank == 0)
{
printf("Enter the value: ");
scanf_s("%d", &value);
MPI_Send(&value, 1, MPI_INT, rank + 1, 0, MPI_COMM_WORLD);
}
else
{
MPI_Recv(&value, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD,
&status);
if (rank < size - 1)
MPI_Send(&value, 1, MPI_INT, rank + 1, 0, MPI_COMM_WORLD);
}
printf("Process %d got %d ", rank, value);
} while (value >= 0);
MPI_Finalize();
return 0;
}
This is output from debug:
'MPIHelloWorld.exe' (Win32): Loaded 'C:\WINDOWS\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'MPIHelloWorld.exe' (Win32): Loaded 'C:\WINDOWS\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'MPIHelloWorld.exe' (Win32): Loaded 'C:\Program Files (x86)\Bonjour\mdnsNSP.dll'. Cannot find or open the PDB file.
MPIHelloWorld.exe has triggered a breakpoint.
MPIHelloWorld.exe has triggered a breakpoint.
The thread 0x3308 has exited with code 0 (0x0).
The thread 0x1dfc has exited with code 0 (0x0).
The thread 0x2e5c has exited with code 0 (0x0).
The program '[4400] MPIHelloWorld.exe' has exited with code 0 (0x0).
UPDATE:
When I press CTRL + 5 I get this error written in my console:
job aborted:
[ ranks ] message
[0] fatal error
Fatal error in MPI_Send:
Invalid rank has value 1 but must be nonnegative and less than 1
Ok, I have finally found an answer!
I couldn't use Cluster Debugger for MPI since I am running Visual Studio 2015
and the problem was that only 1 process was running.
I opened CMD and ran my application using "mpiexec.exe -n 4 myMpiApp.exe" and it worked.
Related
Set the number of nodes to 3, the program will run normally when the following commands are executed:
[changmx#gpu02 mpiTest]$ mpiexec -n 4 -host gpu02,gpu03,gpu04 helloworld
[gpu04:16537] [[37424,0],2] remote spawn is NULL!
[gpu03:01562] [[37424,0],1] remote spawn is NULL!
Hello World! Process 1 of 4 on gpu02
Hello World! Process 3 of 4 on gpu04
Hello World! Process 0 of 4 on gpu02
Hello World! Process 2 of 4 on gpu03
[changmx#gpu02 mpiTest]$ mpiexec -n 4 -host gpu02,gpu03,gpu05 helloworld
[gpu03:01597] [[37381,0],1] remote spawn is NULL!
[gpu05:26312] [[37381,0],2] remote spawn is NULL!
Hello World! Process 0 of 4 on gpu02
Hello World! Process 1 of 4 on gpu02
Hello World! Process 2 of 4 on gpu03
Hello World! Process 3 of 4 on gpu05
But when the number of nodes is 4, the program will neither execute nor exit unless I type Ctrl C to exit:
[changmx#gpu02 mpiTest]$ mpiexec -n 4 -host gpu02,gpu03,gpu04,gpu05 helloworld
[gpu04:16671] [[37833,0],2] remote spawn is NULL!
[gpu03:01731] [[37833,0],1] remote spawn is NULL!
Below is my source code:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <mpi.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
int main(int argc, char *argv[])
{
int myrank, numprocs;
int namelen = 20;
char process_name[namelen];
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Get_processor_name(process_name, &namelen);
printf("Hello World! Process %d of %d on %s\n", myrank, numprocs, process_name);
MPI_Finalize();
}
My Open MPI version is 1.8.8.
This problem should be caused by the incorrect installation of my Open MPI. When I changed the Open MPI version, this problem didn't appear again.
I am a hardware (arduino hobbyist) programmer trying to get into OpenCV but struggling with a random error.
I have been following Adam Hacks youtibe guide to OpenCV and up to very recently it has worked great. I had compiled OpenCV as 32bit as the prebuilt was only available in x64 and my intended application (driving a set of servos via a FT232H usb to I2C adapter) was in 32 bit.
I typed in his code for "Using OpenCV and Haar Cascades to Detect Faces in a Video [C++]" and it worked fine (see below). It identified my face (some of the time) and drew a box round it. Yeah I was very happy.
The code:
#include <opencv2/opencv.hpp>
#include <vector>
using namespace std;
/* Include D2XX header*/
#include "ftd2xx.h"
/* Include libMPSSE header */
#include "libMPSSE_i2c.h"
#include "FT232.h"
using namespace cv;
int main()
{
//FT232 ft232;
//ft232.setUpFT232H();
double scale = 1.0;
CascadeClassifier faceCascade;
faceCascade.load("C:\\OpenCV32\\etc\\haarcascade_frontalface_alt.xml");
VideoCapture cap(0);
if (!cap.isOpened())
return -1;
for (;;)
{
Mat frame;
cap >> frame;
Mat grayscale;
cvtColor(frame, grayscale, COLOR_BGR2GRAY);
resize(grayscale, grayscale, Size(grayscale.size().width / scale, grayscale.size().height / scale));
vector <Rect> faces;
faceCascade.detectMultiScale(grayscale, faces, 1.1, 3, 0, Size(30, 30));
for (Rect area : faces) {
Scalar drawColor = Scalar(255, 0, 0);
rectangle(frame, Point(cvRound(area.x * scale), cvRound(area.y * scale)),
Point(cvRound((area.x + area.width-1)*scale), cvRound((area.y + area.height - 1) * scale)), drawColor);
}
imshow("Webcam Frame", frame);
if (waitKey(30) >= 0)
break;
}
return 0;
}
Then with no intentional changes on my part other that swapping about from one haarcascade to another the program stopped working and threw an unhandled error.
Unhandled exception at 0x76979862 in OpenCV_Nerf.exe: Microsoft C++ exception: cv::Exception at memory location 0x00EFF428. occurred
in this part of the system.cpp code
void error( const Exception& exc )
{
#ifdef CV_ERROR_SET_TERMINATE_HANDLER
{
cv::AutoLock lock(getInitializationMutex());
if (!cv_terminate_handler_installed)
{
if (param_setupTerminateHandler)
cv_old_terminate_handler = std::set_terminate(cv_terminate_handler);
cv_terminate_handler_installed = true;
}
cv_terminate_handler_exception = exc;
}
#endif
if (customErrorCallback != 0)
customErrorCallback(exc.code, exc.func.c_str(), exc.err.c_str(),
exc.file.c_str(), exc.line, customErrorCallbackData);
else if (param_dumpErrors)
{
dumpException(exc);
}
if(breakOnError)
{
static volatile int* p = 0;
*p = 0;
}
throw exc;
#ifdef __GNUC__
# if !defined __clang__ && !defined __APPLE__
// this suppresses this warning: "noreturn" function does return [enabled by default]
__builtin_trap();
// or use infinite loop: for (;;) {}
# endif
#endif
}
the error box pointing to the very last line.
The camera still functions and I have narrowed it down to the line
faceCascade.detectMultiScale(grayscale, faces, 1.1, 3, 0, Size(30, 30));
Build output: (I don't remember the warnings about loss of data first few time,, but I can't be sure)
1>------ Rebuild All started: Project: OpenCV_Nerf, Configuration: Debug Win32 ------
1>Source.cpp
1>D:\Vincent\Documents\Programming\Visual Studio Projects\OpenCV_Nerf\Source.cpp(32,93): warning C4244: 'argument': conversion from 'double' to '_Tp', possible loss of data
1> with
1> [
1> _Tp=int
1> ]
1>D:\Vincent\Documents\Programming\Visual Studio Projects\OpenCV_Nerf\Source.cpp(32,60): warning C4244: 'argument': conversion from 'double' to '_Tp', possible loss of data
1> with
1> [
1> _Tp=int
1> ]
1>OpenCV_Nerf.vcxproj -> D:\Vincent\Documents\Programming\Visual Studio Projects\OpenCV_Nerf\Debug\OpenCV_Nerf.exe
1>Done building project "OpenCV_Nerf.vcxproj".
Debug output (last bit as it was over character count)
'OpenCV_Nerf.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'. Symbol loading disabled by Include/Exclude setting.
'OpenCV_Nerf.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'
'OpenCV_Nerf.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'. Symbol loading disabled by Include/Exclude setting.
'OpenCV_Nerf.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'
'OpenCV_Nerf.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'. Symbol loading disabled by Include/Exclude setting.
'OpenCV_Nerf.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'
'OpenCV_Nerf.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'. Symbol loading disabled by Include/Exclude setting.
'OpenCV_Nerf.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'
The thread 0x31a8 has exited with code 0 (0x0).
The thread 0x1f70 has exited with code 0 (0x0).
The thread 0x3668 has exited with code 0 (0x0).
The thread 0x3698 has exited with code 0 (0x0).
The thread 0x3a34 has exited with code 0 (0x0).
The thread 0x374 has exited with code 0 (0x0).
The thread 0x5d8 has exited with code 0 (0x0).
The thread 0x3288 has exited with code 0 (0x0).
The thread 0x35bc has exited with code 0 (0x0).
The thread 0x348c has exited with code 0 (0x0).
The thread 0x3968 has exited with code 0 (0x0).
The thread 0x8c0 has exited with code 0 (0x0).
The thread 0x1068 has exited with code 0 (0x0).
The thread 0x1ef8 has exited with code 0 (0x0).
The thread 0x3a30 has exited with code 0 (0x0).
The thread 0x184c has exited with code 0 (0x0).
The thread 0x37f8 has exited with code 0 (0x0).
The thread 0x18b4 has exited with code 0 (0x0).
The thread 0x3380 has exited with code 0 (0x0).
The thread 0x3bf8 has exited with code 0 (0x0).
'OpenCV_Nerf.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvproc.dll'. Symbol loading disabled by Include/Exclude setting.
Exception thrown at 0x76979862 in OpenCV_Nerf.exe: Microsoft C++ exception: cv::Exception at memory location 0x00FCF7EC.
Unhandled exception at 0x76979862 in OpenCV_Nerf.exe: Microsoft C++ exception: cv::Exception at memory location 0x00FCF7EC.
I am completely stumped and would really appreciate any help or pointers I could get.
Regards
I need to connect OpenMPI library to Visual Studio 2015. I can't use other liblaries instead of OpenMPI. I setup OpenMPI_v1.6.2-1_win32.exe and specified:
Include Directories: C:\Program Files\OpenMPI_v1.6.2-win32\include
Library Directories: C:\Program Files\OpenMPI_v1.6.2-win32\lib
Additional Dependencies: libmpi.lib
Open MP Support: Yes
When I try to compile the code:
#include <stdio.h>
#include "mpi.h"
int main(int argc, char* argv[]) {
int ProcNum, ProcRank, RecvRank;
MPI_Status Status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &ProcNum);
MPI_Comm_rank(MPI_COMM_WORLD, &ProcRank);
if (ProcRank == 0) {
// Действия, выполняемые только процессом с рангом 0
printf("\n Hello from process %3d", ProcRank);
for (int i = 1; i < ProcNum; i++) {
MPI_Recv(&RecvRank, 1, MPI_INT, MPI_ANY_SOURCE,
MPI_ANY_TAG, MPI_COMM_WORLD, &Status);
printf("\n Hello from process %3d", RecvRank);
}
}
else // Сообщение, отправляемое всеми процессами,
// кроме процесса с рангом 0
MPI_Send(&ProcRank, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
Visual Studio show errors:
1>------ Build started: Project: OpenMPISample, Configuration: Debug
Win32 ------ 1>Source.obj : error LNK2001: unresolved external symbol
_ompi_mpi_comm_world 1>Source.obj : error LNK2001: unresolved external symbol _ompi_mpi_int 1>C:\Users\Andriy\Documents\Visual Studio
2015\Projects\OpenMPISample\Debug\OpenMPISample.exe : fatal error
LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
How to connect OpenMPI library to Visual Studio 2015 correctly? Thanks in advance!
I downloaded and installed mpich2-1.0.8p1-win-x86-64.msi from the console with the administrator rights. I created empty win32 console project, I created file code.cpp and I pasted this example code.
#include <stdio.h>
#include "mpi.h"
int main(int argc, char* argv[])
{
int ProcNum, ProcRank, RecvRank;
MPI_Status Status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &ProcNum);
MPI_Comm_rank(MPI_COMM_WORLD, &ProcRank);
if (ProcRank == 0)
{
printf("\n Hello from process %3d", ProcRank);
for (int i = 1; i < ProcNum; i++)
{
MPI_Recv(&RecvRank, 1, MPI_INT, MPI_ANY_SOURCE,
MPI_ANY_TAG, MPI_COMM_WORLD, &Status);
printf("\n Hello from process %3d", RecvRank);
}
}
else
MPI_Send(&ProcRank, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
Later I went to project properties to VC++ Directories and added include directories and library directories. In Linker/Input/Additional Dependencies I wrote mpi.lib and in C/C++/Language I allowed Open MP Support. When I compiled my project I have got strange errors. Can you help me? I can't understand what I made wrong, because I did it with tutorials.
Your first (and only) warning states that you are linking a 64-bit library with a 32-bit build. You need to either provide a 32-bit library or build for a 64-bit architecture to get rid of the linker errors.
My test program works fine when I run multiple processes on a single machine.
$ ./mpirun -np 2 ./mpi-test
Hi I'm A:0
Hi I'm A:1
A:1 sending 11...
A:1 sent 11
A:0 received 11 from 1
all workers checked in!
When I run the same program on multiple hosts the process is spawned on each host, but MPI_Send never returns.
$ ./mpirun -np 2 -host A,B ./mpi-test
Hi I'm A:0
Hi I'm B:1
B:1 sending 11...
I've tried a couple other sample MPI programs I found and I ran into the same problem. Any idea what is going wrong?
EDIT: this also runs on a remote machine if all the processes are spawned on that machine.
Code:
#include <mpi.h>
int main(int argc, char** argv)
{
MPI::Init();
int rank = MPI::COMM_WORLD.Get_rank();
int size = MPI::COMM_WORLD.Get_size();
char name[256];
int len;
MPI::Get_processor_name(name, len);
printf("Hi I'm %s:%d\n", name, rank);
if (rank == 0) {
while (size > 1) {
int val;
MPI::Status status;
MPI::COMM_WORLD.Recv(&val, 1, MPI::INT, MPI::ANY_SOURCE, MPI::ANY_TAG, status);
int source = status.Get_source();
printf("%s:0 received %d from %d\n", name, val, source);
size--;
}
printf("all workers checked in!\n");
}
else {
int val = rank + 10;
printf("%s:%d sending %d...\n", name, rank, val);
MPI::COMM_WORLD.Send(&val, 1, MPI::INT, 0, 0);
printf("%s:%d sent %d\n", name, rank, val);
}
MPI::Finalize();
return 0;
}
EDIT: ompi_info
$ ./mpirun --bynode -host A,B --tag-output ompi_info -v ompi full --parsable
[1,0]<stdout>:package:Open MPI user#A Distribution
[1,0]<stdout>:ompi:version:full:1.4.3
[1,0]<stdout>:ompi:version:svn:r23834
[1,0]<stdout>:ompi:version:release_date:Oct 05, 2010
[1,0]<stdout>:orte:version:full:1.4.3
[1,0]<stdout>:orte:version:svn:r23834
[1,0]<stdout>:orte:version:release_date:Oct 05, 2010
[1,0]<stdout>:opal:version:full:1.4.3
[1,0]<stdout>:opal:version:svn:r23834
[1,0]<stdout>:opal:version:release_date:Oct 05, 2010
[1,0]<stdout>:ident:1.4.3
[1,1]<stdout>:package:Open MPI user#B Distribution
[1,1]<stdout>:ompi:version:full:1.4.3
[1,1]<stdout>:ompi:version:svn:r23834
[1,1]<stdout>:ompi:version:release_date:Oct 05, 2010
[1,1]<stdout>:orte:version:full:1.4.3
[1,1]<stdout>:orte:version:svn:r23834
[1,1]<stdout>:orte:version:release_date:Oct 05, 2010
[1,1]<stdout>:opal:version:full:1.4.3
[1,1]<stdout>:opal:version:svn:r23834
[1,1]<stdout>:opal:version:release_date:Oct 05, 2010
[1,1]<stdout>:ident:1.4.3
I ended up upgrading to 1.5.3 on A and installing 1.5.3 on C. I'm not sure whether it was the upgrade, or an issue with B, but everything is working now.
For reference:
original setup: node A (arch linux, Open MPI 1.4.3), node B (ubuntu, Open MPI
1.4.3)
working setup: node A (arch linux, Open MPI 1.5.3), node C (arch linux,
Open MPI 1.5.3)
The usual reason for this is that something is not set up properly on the remote host; it could be login/network problems, or that the MPI libraries/executables or the program itself isn't found on the remote host.
What happens if you try
mpirun -np 2 -host A,B hostname
?