You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem: To get the output of a shell command, you must write it to a temporary file and then read it into Fortran.
See the current version of the subroutine find_number_of_cpus:
subroutine find_number_of_cpus(this)
class(linux_nodes), intent(inout) :: this
integer :: nunit
logical :: ex
character(len=:), allocatable :: file_name
! todo: get total number of linux cpus
call execute_command_line ("echo $(nproc --all) > /tmp/forclust_ncpus")
file_name = '/tmp/forclust_ncpus'
inquire(file=file_name, exist=ex)
if (ex) then
open(newunit=nunit, file=file_name, action='read')
read(nunit, *) this%ncpus
close(nunit)
else
this%ncpus = 1
! error stop "file not found: "//file_name
end if
end subroutine find_number_of_cpus
Solution: Use the get_command_as_string function in the pipes_module module from here. With this function a new version looks like as follows:
subroutine find_number_of_cpus(this)
use :: pipes_module, only: get_command_as_string
class(linux_nodes), intent(inout) :: this
character(len=:), allocatable :: ncpu_char
ncpu_char = get_command_as_string('nproc --all')
read(ncpu_char,*) this%ncpus
end subroutine find_number_of_cpus
The text was updated successfully, but these errors were encountered:
gha3mi
changed the title
Use "get_command_as_string" function
Use function "get_command_as_string"
Jan 18, 2023
Problem: To get the output of a shell command, you must write it to a temporary file and then read it into Fortran.
See the current version of the subroutine
find_number_of_cpus
:Solution: Use the
get_command_as_string
function in thepipes_module
module from here. With this function a new version looks like as follows:The text was updated successfully, but these errors were encountered: