Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29251 Discussions

openMP/MPI parallelization of external standalone program

Michal_Kvasnicka
Beginner
522 Views
Hello forum,

is possible to parallelize via OpenMP/MPI the following fragment of fortran code:

do i = 1,n
call ext_run(input(i), output(i))
end do


where subroutine ext_run(input,output) execute external single thread program by SYSTEMQQ (commandline) function. For example: SYSTEMQQ ('extprog.exe < input_i.dat > output_i.dat'), where input_i and output_i are auxiliary data files which were created using input(i) or output(i) parameters.

I will be happy for some simple examples. Thanks ...

Michal
0 Kudos
2 Replies
jimdempseyatthecove
Honored Contributor III
522 Views
Untesteded pseudo code
pidTable = 0
do i = 1, n
pid = fork()
if(pid .lt. 0) exit ! vfork failed
if(pid == 0) then
call exit_run(input(i), output(i))
call _exit(0) ! not exit(nnn) and in case of return of exit_run
end if
! fork successful and masterprocess
pidTable(i) = pid ! save pid of child process
end do
! check for errors and wait for child processes to complete
status = 0
anyStatus = 0
do i=1,n
if(pidTable(i) == 0) exit ! no more processes
if(waitpid(pidTable(i), status, 0) != pidTable(i)) anyStatus = status
end do
if((pid.lt. 0).or. (anyStatus .ne.0)) write(*,*) "oops"

Jim Dempsey
0 Kudos
Michal_Kvasnicka
Beginner
522 Views
Question for Intel fortran guys:

Arethe fortran functions: SYSTEM andSYSTEMQQ thread-safe?
0 Kudos
Reply