therefore the code will not wait until I close the gnuplot popup window. I mean the gnuplot and the program are basically independent. It works fine with Intel Fortran, see below,
However, when the same code compile and run with gfortran, when the gnuplot windows popup, I have to close it, then the problem will continue to run.
Otherwise, if I do not close the gnuplot windows as below, the program pause. Unless I close the popup window, then the code resume.
I donât know how gfortran implements EXECUTE_COMMAND_LINE (I wrote the ifort implementation), but the standard says that asynchronous execution is not required to be supported:
If the processor supports command line execution, it shall support synchronous and may support asynchronous execution of the command line. (16.9.73p4 - emphasis mine)
wait=.false. is a request. The âprocessorâ doesnât have to honor it. Youâll want to check with the gfortran documentation to see whether this is supposed to be supported, and if it is, file a bug report. There are some other things in the standard that are not required to be supported - Annex A in the standard lists all processor dependencies. (Curiously, though - not this one - I will look into that.)
For Intel, the Windows and Linux/Mac implementations are different. Windows uses CreateProcess and WaitForSingleObject - I no longer recall exactly what I did for Linux/Mac, but I know that asynchronous behavior was supported.
It has been ages since I had a problem with EXECUTE_COMMAND_LINE(3f). What OS and compiler version are you using? This works as expected with gfortran, ifort, and nvfortran on any Linux and Unix machine I have access to. So this program does not immediately print out the version and compiler information?
program demo_exec
use, intrinsic :: iso_fortran_env, only : compiler_version, compiler_options
implicit none
integer :: exitstat,cmdstat
character(len=256) :: cmdmsg
cmdmsg=''
call execute_command_line("sleep 30", exitstat=exitstat,wait=.false.,cmdstat=cmdstat,cmdmsg=cmdmsg)
if(cmdstat.ne.0.or.exitstat.ne.0)then
write(*,*)cmdstat,exitstat,trim(cmdmsg)
endif
print '(4a)', &
'This file was compiled by ', &
compiler_version(), &
' using the options ', &
compiler_options()
call execute_command_line("ps", exitstat=exitstat,wait=.false.,cmdstat=cmdstat,cmdmsg=cmdmsg)
end program demo_exec
Thank you @urbanjost !
I am on Windows 10 and using Intel OneAPI 2021.4.
The intel Fortran is doing exactly what I want, the code and the gnuplot in call execute_command_line(gnuplot 'gnuplot persistent', xxx, wait = .false.) they run independently. so I can get real time plot all the time. Then gnuplot can reread the file and plot like every 1 second interval.
However gfortran at on my Windows behave like I described, the wait = .false. have no difference from wait = .true..
I also tested gnuplot on ubuntu with gfortran with wait = .false. . This time wait = .false. seems working, However the gnuplot popup window does not update automatically at every 1 second. I need to close the gnuplot popup window, then it popup gain, close, popup gain, repeat⌠I do see each time the content in the popup window updates, but I have to manually repeat this close->popup loop,
However, intel OneAPI on windows and ubuntu behave the same, I do see the gnuplot update in real time. So it seems gfortranâs wait = .false. is different from intelâs. I would prefer the way Intel does.
In terms of speed, on Linux, gfortran is not bad actually. Roughly the same as Intelâs, perhaps 10-20% slower but still decent. However, intelâs performace is consistent on windows and linux. While gfortranâs speed on windows (at least for my code) seems is about 2-3 slower than intelâs. My gfortran flag is