'mpirun vs "./" when to use?
So I'm configuring a batch script to run my code on a cluster. It runs on my workstation with both
./<executable> name
and
mpirun -n <# of cores> executable name
What is the difference and why does mpirun sometimes fail/hang?
Solution 1:[1]
MPI is the Message Passing Interface used for parallelization (running the code over multiple cores). mpirun is a command for launching MPI jobs. Your executable needs to be specifically programmed and built for MPI to take advantage of the parallelization. Otherwise mpirun just runs the same job n times, once on each core.
When you use ./, you're running the program on a single process, so it won't run with parallelization (at least not with MPI parallelization).
The operating system needs to know where the executable is located in order to launch it. Possible locations for the executables are defined in the PATH environment variable, which is typically defined with /usr/bin and possibly a few other directories. If the executable is not in a directory defined in the PATH, then the full path needs to be provided explicitly, e.g. /opt/some_third_party_application/bin/some_third_party_executable
The single dot . represents the current working directory. It's common for . to not be included in PATH (though sometimes it is included). It's recommended for security purposes not to include it, so that executables (including viruses) in random directories don't get launched accidentally. That means <executable> won't launch on its own if it's located in the current directory. The path to it needs to be provided, but . counts as a path (representing the current directory. Hence ./<executable> launches the program, the ./ indicating that execution is deliberately intended.
mpirun does not need a path to be provided since it's located in /usr/bin, in the PATH variable.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rizzer |
