- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So I am porting a Fortran code from Linux to Windows. The program is parallelised with MPI (specifically Intel MPI). The porting of the serial part of the code was successful and it runs on Windows without any hitch.
In the MPI parallel part of the code, there is a line which I assume is checking whether the program has been called with MPI or not.
call get_environment_variable("I_MPI_MPIRUN", value = env_var, status = ev_status)
if(ev_status .eq. 1) call exec_mpirun(IMPI)
From what I can understand if the program is called with mpirun on Linux the I_MPI_MPIRUN environment variable is defined to some value. The program checks for that and if MPI isn't running, it then calls the function exec_mpirun(). IMPI is a parameter defined as 1. The exec_mpirun() is a C function which runs execvp("mpirun", "mpirun","--map-by","node", "dmrcc_mpi"). dmrcc_mpi is the executable that needs to run.
However, I can't find any Intel MPI documentation where the I_MPI_MPIRUN environment variable is mentioned. And I am not even sure that the same variable is used for Windows. For windows, the MPI executable is called with mpiexec, which also leads me to suspect the same environment variable wouldn't be used.
So, is there any way to check whether the program has been called with MPI from within a Fortran code?
And is I_MPI_MPIRUN variable set by mpiexec on Windows? Or is any other variable set?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Find the MPI code of sample.f below:
program main
implicit none
include 'mpif.h'
integer ierr,size,rank,temp
call MPI_INIT (ierr)
call MPI_COMM_SIZE (MPI_COMM_WORLD, size, ierr)
temp=ierr
call MPI_COMM_RANK (MPI_COMM_WORLD, rank, ierr)
if (rank.eq.0 .and. size.ge.1) then
print *, 'MPI_COMM_SIZE returned ',ierr
print *,'MPI Launched with ',size,' ranks'
end if
!write your code here
call MPI_FINALIZE (ierr)
end
I am using the below FORTRAN code test.f90 to launch MPI executable file sample.exe
PROGRAM test_getenv
call execute_command_line('mpiexec -np 4 sample.exe')
END PROGRAM
On executing test.exe the output will be as follows:
If MPI is launched, then we will get "4" ranks in output as we passed np=4 in test.f90. else by default, we get "1" rank.
Thus we can confirm whether MPI is launched successfully or not.
>>"Would the function return an error if the program wasn't launched with MPI?"
Yes, you can refer to the code sample.f and if ierr=0, then call to MPI_COMM_SIZE is successful.
Thanks & Regards,
Santosh
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for reaching out to us.
>>"So, is there any way to check whether the program has been called with MPI from within a Fortran code?"
Yes, by setting a few debug statements like printing No. of processes launched in MPI source code.
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
>>"And is I_MPI_MPIRUN variable set by mpiexec on Windows? Or is any other variable set?"
In windows, as there is no mpirun and there exists only mpiexec it isn't necessary to check for I_MPI_MPIRUN
Thanks & Regards,
Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, Thanks for the reply.
I am actually using FORTRAN, does the same code work in it? The code snippet you posted looks like C/C++ code.
So, what would be the difference between launching the process with or without MPI for the MPI_Comm_size() function?
Would the function return an error if the program wasn't launched with MPI?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Find the MPI code of sample.f below:
program main
implicit none
include 'mpif.h'
integer ierr,size,rank,temp
call MPI_INIT (ierr)
call MPI_COMM_SIZE (MPI_COMM_WORLD, size, ierr)
temp=ierr
call MPI_COMM_RANK (MPI_COMM_WORLD, rank, ierr)
if (rank.eq.0 .and. size.ge.1) then
print *, 'MPI_COMM_SIZE returned ',ierr
print *,'MPI Launched with ',size,' ranks'
end if
!write your code here
call MPI_FINALIZE (ierr)
end
I am using the below FORTRAN code test.f90 to launch MPI executable file sample.exe
PROGRAM test_getenv
call execute_command_line('mpiexec -np 4 sample.exe')
END PROGRAM
On executing test.exe the output will be as follows:
If MPI is launched, then we will get "4" ranks in output as we passed np=4 in test.f90. else by default, we get "1" rank.
Thus we can confirm whether MPI is launched successfully or not.
>>"Would the function return an error if the program wasn't launched with MPI?"
Yes, you can refer to the code sample.f and if ierr=0, then call to MPI_COMM_SIZE is successful.
Thanks & Regards,
Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
We haven't heard back from you. Is the solution provided helped? Please let us know if the issue still persists.
Thanks & Regards,
Santosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Many thanks for the solution. I haven't actually used the solution yet, I have found many other problems in the code (different MPI processes are trying to write to the same file at the same time etc.), which I am trying to fix before I can test whether it runs without error or not.
But I think your solution is right, so I will mark it as accepted.
Thanks,
SRM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for accepting as a solution.
As your issue has been resolved, we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.
Thanks & Regards,
Santosh

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page