'mpirun' is not recognized as an internal ort external commands, - c++

I need to make a small openMP project. I took the example from the www.openmp.org. I can compile it with /openmp option within VC++ 2005. But, When I try to run the program, I am facing the "'mpirun' is not recognized as an internal ort external commands, operable program or batch file" error. When I search the net. I found this mpirun and mpiexec is not located XP desktop. They are only in server distribution. How can run/debug openMP programs on windows?
Or should I need to go Linux?

You mention that you are using OpenMP - you shouldn't actually need to use mpirun or mpiexec, as you would with MPICH or OpenMPI programs. OpenMP works in a fairly different way than message-passing libraries: OpenMP uses multiple threads within the same process, but MPICH and OpenMPI use multiple processes.
So if I understand your question correctly, you should be able to just run your executable without using mpirun or mpiexec.
If, on the other hand, you're using MPICH, the mpiexec program lives in
{ProgramFiles}\MPICH2\bin.
Good luck!

Related

VS2017 - How to configure project for remote debugging

I want to create an MP3 player on my Raspberry Pi (OS: Raspbian). The problem is, that i don't have any experience with Linux programming, and I'm having a huge problem with project configuration, becouse of cross platform compiling. I want to add two liblaries:
mpg123
libao
I'm able to compile the code on linux machine with gcc -O2 test.cpp -lmpg123, but I can't force Visual Studio to make see those libs.
I'm also having a problem with using wiringPi lib while I'm trying to remote debugging my program, since I have to run it as root for GPIO configuration. Is there any way for any way to force Visual Studio to run my compiled code with root privilages?
Personally I come from a long history of C/C++/MFC/Windows programming with no Linux experience at all. I started programming for the Raspberry a year or so ago, when I got one from my son for my birthday. With a C/C++ history it's really not that hard, but you just have to read in a bit because on Linux a lot is the same, and a lot isn't :). Just read and read and in time, you're an experienced Linux programmer! It takes some time I'm afraid.
So, I'm sort of an experienced newbie on this I think :). I found a lot of info on www.die.net (and other Linux man pages). If you search there for a function, say printf(), look at the (3) pages - they explain how you should use 'm.
But although VS2017 does a really good job on this, it's not always going as smooth as you would like. Sometimes it's just necessary to reboot your Raspberry, restart VS and try again. The Linux cross-compiling is quite new in VS and isn't perfect yet.
A few tips:
Use a Raspberry with a fresh Stretch image to start with. Of course after a sudo apt-get update && sudo apt-get -y upgrade.
Set the debugger in Visual Studio to gdb instead of gdbserver. This will prevent certain debugging problems.
Place all your source files (.h and .cpp) in the main folder of your project alongside the main.cpp. If you place them in different directories and then include in your project, you can debug your program but you won't be able to step through.
Start simple and debug your program often when you're developing. Don't add too much code before your next check. In a cross-compile setup there are just a lot more things than normal that can (and will) go wrong.
VS2017 has default Linux include files in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\Linux\include. If you need others, place them in a folder of you own and include the path.
With cross-compiling VS itself doesn't do any compiling, you use it to maintain your project. When the project has to be compiled, all necessary files are copied to the Raspberry and the compiler and linker there are invoked by VS.
On your question how to configure a project for remote debugging: it's probably best to start with the Blink example in Visual Studio 2017 (File, New, Project, Installed, Visual C++, Cross Platform, Linux => Blink). It should run without problems. From there, you can build further on your project.
In the Blink example, they use wiringPiSetupSys() and the remote command gpio export 17 out to run your program without sudo. I've found that changing that to wiringPiSetup() and disabling the remote command, it still is possible to run and debug the program. On the Raspberry I can run the program from it's folder by issuing ./[programname]. If that doesn't work for you, you could run the program by issuing sudo ./[programname].

Multi-platform way to check if a process is running via the process name

I'm making a program that will hopefully run on Windows, AppleOS, and GNU/Linux. For the program I need to check if "steamchildmonitor" is running. I know I could do this using ppgrep on linux. But I would rather have one piece of code that runs on all systems. Is this possible, if not what would I use to check if it is running on Windows (I believe the AppleOS implementation would be the same as the linux one). Thanks in advance!

Eclipse PTP OpenMPI parallel run/debug

Can someone give instructions on how to run/debug an OpenMPI (C/C++/Fortran) program in Eclipse PTP using the actual parallel run/debug modes on a local machine?
I've set a local connection in the 'Remote Environments' section. If I specify the actual program executable as the executable then eclipse gets stuck with 'submit interactive' and 'Launching... Submitting the job...' in the progress window, and I'm left with the specified number of processes of the program running at full CPU indefinitely. If I specify another program, like mpirun or mpiexec, and provide the necessary arguments to get to the program executable then the only difference is that I have the same number of mpirun's running at 0 CPU.
I should add that if I actually select "Local" under "Connection Type" then I get an error:
Failed to execute command: ompi_info -a --parseable
Reason: Cannot run program "ompi_info": Unknown reason
even though that command works fine from the command line and runs successfully when connecting to local host as setup in the 'remote environments'
I've seen the guides on the Eclipse website, but they're no help. I've checked [1] and [2], but I still get this working right.
I can get a program running successfully in parallel by treating it like a normal program and setting the executable to mpiexec and providing the necessary arguments, but I want to do actual parallel debugging, so this doesn't suffice.
EDIT:
I should be more specific. I know there are other methods of debugging, but Eclipse PTP (parallel tools platform) should be able to handle this perfectly, so I'm looking for an explanation from someone who has setup Eclipse PTP on their local machine such that they can use a parallel run configuration and the parallel debugging tools.
Please ask your question on the ptp-user mailing list.
https://dev.eclipse.org/mailman/listinfo/ptp-user
Sounds like openmpi isn't in the path available within eclipse
In fact, this is in the PTP FAQ on https://wiki.eclipse.org/Parallel_Tools_Platform_FAQ#Q:_I_get_the_error_.22Failed_to_execute_command:_ompi_info_-a_--parseable.22_when_I_use_the_Open_MPI_target_configuration_on_my_Mac
I've never actually used the Eclipse IDE, but I debug my MPI code using xterm and gdb:
mpirun -np 2 xterm -e gdb -ex run ./tool
Not exactly what you where after, but perhaps it helps...
Not sure which OS you're using, but I had this issue on MacOS. It's because Eclipse doesn't run .bash_profile or .bashrc, so its environment (namely PATH) won't have everything it needs. You could try to edit the PATH variable to include it by some other means (which I found to be overly complicated on Mac), OR you can just run the eclipse executable from a shell so that it inherits your typical environment. For me this was located at:
~/eclipse/parallel-neon/Eclipse.app/Contents/MacOS/eclipse
Then eclipse was able to detect OpenMPI just fine (PATH contained /usr/local/bin).

How to make a linux command-line program work in windows?

I'm a beginner with programming, and I've been doing work in C/C++ in Ubuntu. When I tell something to cin/cout/cerr or printf/scanf or take arguments from the command line, this all happens from the linux terminal in Ubuntu.
Now if I want to run these same programs (very simple programs, beginner-level) and run them in Windows, how do I run them from the Windows command line? A previous course I've taken had us download cygwin to simulate the linux command line in windows, but what if I want to just run the program from the ordinary windows command line? Is that possible, and does it require modification of the software?
You can cross-compile the program for Windows from linux.
On Ubuntu, process is basically this:
sudo apt-get install wine mingw32 mingw32-binutils mingw32-runtime
...
i586-mingw32msvc-g++ -o myProgram.exe myProgram.cpp
Easy, right? Google for "ubuntu cross-compile windows," there's a ton of information out there.
It's exactly the same. You run cmd and write the command (almost) exactly as you would in Linux.
For example, if you build your program to program, you would run it in Linux like this:
./program --option1 -o2 file1 file2
And in Windows, first you have to make the output have a .exe suffix and then in cmd you would write:
program.exe --option1 -o2 file1 file2
Basically saying, cmd is Windows' terminal. It's nowhere near as good as the Linux terminal, but that would be all you get without installing additional software.
cin/cout/cerr and printf/scanf/fprintf(stderr, ...) use the standard C preopened files stdin, stdout and stderr which are defined both in Linux and Windows. Once you run the application from Windows' terminal (cmd), you see the input/output exactly as you would in the Linux terminal. I/O redirection is also very similar.
cin and cout, and printf and scanf, work much the same in Windows as they do in Linux. (I'm pretty sure cerr does too, but that one i'm not 100% sure about. At the very least, though, it's there and works.) The biggest difference is that Windows typically won't expand wildcards (stuff like *.txt) before running your program; you have to do that yourself in most cases.
Basically, as long as the app doesn't use anything specific to Linux or GCC, you could just recompile it on the target machine using whatever compiler you like to test.
If you don't want to recompile...well...good luck with that. Even Cygwin won't run native Linux binaries. You'd need a virtual machine with Linux on it.
Well, if you program is portable and not using any features specific to Linux, you would have to compile it from source on Windows to make it work on Windows.
You would need the GCC tool-chain for windows to do that, which you can get from the TDM-GCC homepage. Its MinGW internally and the installer allows you to choose the features you want to install as well as the target directory for installation. It also adds itself to Windows path so that the compiler commands are available from the shell prompt.
I have to do the cross compilation regularly and it works without any issues for me. There is one change which you must make if your project is using Makefiles. For the target binary, such as <target>.out in linux, you would have to edit your Makefile and rename it to <target>.exe so that it runs on the command line. If you are not using Makefiles and just doing gcc <file.c>, the a.exe is produced by default (similar to a.out in Linux).
Say you have this program code you want to run on UNIX and Windows:
#include <stdio.h>
int main()
{
printf("Hi\n");
return 0;
}
When you type a command in a UNIX shell it will be something like this.
/usr/home/bobby# gcc main.c
/usr/home/bobby# ./a.out
Hi
/usr/home/bobby#
On Windows you'd have to first choose your development environment/compiler. Without going to something like Cygwin, you could install the Windows SDK or Visual studio (although if the latter you might just want to develop in the GUI).
Start -> Run -> cmd /k ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"" x86
C:\Windows\system32>cd c:\bobby
C:\bobby>cl main.c
C:\bobby>main.exe
Hi
C:\bobby>
When a C program is compiled into an executable this is done in a system dependent way. On Ubuntu the ELF format is used and on Windows we have PE.
When you start a process the ELF or PE is read giving instructions/map on how to allocate memory and where to put various pieces of the process in a virtual memory table. Further it links up to dynamically loaded libraries, already in physical memory, that it share with other processes which is using the same libraries. Or if the dynamic libraries is not present load them. (Linux .so, windows .dll). If it has static libraries these are allocated and linked in (Linux .a, Windows .lib). - Very simplified.
Memory restrictions etc are inherited from previous process.
Environment variables are put into the running environment for the process. This being paths, arguments, etc. Then main() is added to the stack and called.
Now everything happening before main is called and how linkage etc are resolved, and so many other things, depends on the system. This is why one simply can't run an executable compiled on Linux on Windows.
Using cygwin one is simply creating a virtual environment where those linkages etc are the same and would work. One create an ELF environment.
To get it linked for native Windows command line one would have to compile for Windows. On that matter I see there is lots of answers already.
The ELF and PE, as on different systems, also have different ways of handling environment variables etc. What these are etc. So i.e. file expansion is handled differently. However both running processes has the default streams like stderr, stdout and stdin. But below your code in C they are not the same.
It is like driving a diesel vs a petrol car. Much is the same but under the hood quite a few things is different.
Be aware that i.e. signals are handled different on Windows.

Netbeans MPI c++ how to start?

Hello everyone I just staring developing c++ under netbeans/ubuntu(x64) and now I am staring with MPI. How can I compile, test,run mpi applications under. Thanks a lot.
Till now, I've found only this IDE for MPI on Linux: Geany (a tutorial is here.)
But I keep searching...
If anyone find better IDE, please share under this question...
There is an Eclipse plug-in for parallel programming, including MPI: http://www.eclipse.org/ptp/
To build, change the C++ compiler in NetBeans's C/C++ options to be /path/to/mpicc.
As for running, MPI applications are usually invoked with mpirun. This is done either via the command line (on your PC) or via a batch description file (on a cluster with OpenPBS, LoadLeveler, or similar scheduler). I've never tried to run MPI via an IDE, though NetBeans does have an option for the debugger command, so you might be able to try that and see what happens.