| 1 |
! PR debug/118790 |
| 2 |
! { dg-do compile } |
| 3 |
! { dg-options "-O2 -g -fopenmp --param ggc-min-expand=0 --param ggc-min-heapsize=0" } |
| 4 |
|
| 5 |
module ec_args_mod |
| 6 |
private |
| 7 |
public :: ec_argc, ec_argv, ec_args |
| 8 |
interface |
| 9 |
function ec_argc() bind(c,name="ec_argc") result(argc) |
| 10 |
end function |
| 11 |
end interface |
| 12 |
contains |
| 13 |
function ec_argv(iarg) result(argv) |
| 14 |
use, intrinsic :: iso_c_binding |
| 15 |
character(len=:), allocatable :: argv |
| 16 |
type(c_ptr), pointer :: argv_cptrs(:) |
| 17 |
argv = to_string (argv_cptrs(iarg+1), 1024) |
| 18 |
end function |
| 19 |
subroutine ec_args() |
| 20 |
use, intrinsic :: iso_c_binding |
| 21 |
integer :: argc |
| 22 |
type(c_ptr) :: argv(512) |
| 23 |
if (ec_argc() == 0) then |
| 24 |
call read_command_line(argc,argv) |
| 25 |
end if |
| 26 |
end subroutine |
| 27 |
function to_string(cptr,maxlen) result(string) |
| 28 |
use, intrinsic :: iso_c_binding |
| 29 |
character(len=:), allocatable :: string |
| 30 |
type(c_ptr) :: cptr |
| 31 |
character(kind=c_char,len=1), pointer :: s(:) |
| 32 |
call c_f_pointer (cptr, s, (/maxlen/)) |
| 33 |
do |
| 34 |
if (s(i) == c_null_char) exit |
| 35 |
i = i + 1 |
| 36 |
end do |
| 37 |
nchars = i - 1 |
| 38 |
allocate (character(len=(nchars)) :: string) |
| 39 |
do i=1,nchars |
| 40 |
string(i:i) = s(i) |
| 41 |
end do |
| 42 |
end function |
| 43 |
subroutine read_command_line(argc,argv) |
| 44 |
use, intrinsic :: iso_c_binding |
| 45 |
integer, parameter :: cmd_max_len = 1024 * 512 |
| 46 |
integer(c_int) :: argc |
| 47 |
type(c_ptr) :: argv(:) |
| 48 |
character(kind=c_char,len=1), save, target :: args(cmd_max_len) |
| 49 |
character(kind=c_char,len=cmd_max_len), save, target :: cmd |
| 50 |
character(kind=c_char,len=cmd_max_len) :: arg |
| 51 |
integer(c_int) :: iarg, arglen, pos, ich, argpos |
| 52 |
do ich=1,len(cmd) |
| 53 |
if (cmd(ich:ich) == " ") then |
| 54 |
cmd(ich:ich) = c_null_char |
| 55 |
end if |
| 56 |
end do |
| 57 |
do iarg=1,argc |
| 58 |
do ich=1,arglen |
| 59 |
args(pos) = arg(ich:ich) |
| 60 |
end do |
| 61 |
args(pos) = c_null_char; pos = pos+1 |
| 62 |
argv(iarg+1) = c_loc(args(argpos)) |
| 63 |
end do |
| 64 |
end subroutine |
| 65 |
end module |
| 66 |
module mpl_mpif |
| 67 |
integer mpi_status_size |
| 68 |
end module mpl_mpif |
| 69 |
subroutine ec_meminfo(ku,cdstring,kcomm,kbarr,kiotask,kcall) |
| 70 |
use mpl_mpif |
| 71 |
interface |
| 72 |
subroutine ec_pmon(energy,power) |
| 73 |
end subroutine ec_pmon |
| 74 |
end interface |
| 75 |
character(len=*), intent(in) :: cdstring |
| 76 |
integer :: ii,jj,i,j,k,myproc,nproc,len,error,nodenum,jid |
| 77 |
integer :: tasksmall,nodehuge,memfree,cached,nfree |
| 78 |
integer :: nnuma |
| 79 |
integer,dimension(:),allocatable,save :: smallpage,hugepage |
| 80 |
integer :: n18 |
| 81 |
integer,dimension(:,:),allocatable,save :: node, bucket |
| 82 |
character(len=256) :: clstr |
| 83 |
character(len=20) :: nodename,lastnode,clmaxnode |
| 84 |
character(len=160) ::line |
| 85 |
character(len=5+1+len(cdstring)) :: id_string |
| 86 |
integer :: irecv_status(mpi_status_size) |
| 87 |
logical :: llnocomm, llnohdr |
| 88 |
logical, save :: llfirst_time = .true. |
| 89 |
type ranknode_t |
| 90 |
integer :: nodenum |
| 91 |
integer :: pid |
| 92 |
integer :: rank_world |
| 93 |
integer :: rank |
| 94 |
integer :: iorank |
| 95 |
integer :: nodemaster |
| 96 |
integer, allocatable :: coreids(:) |
| 97 |
character(len=len(clstr)) :: str |
| 98 |
end type |
| 99 |
type (ranknode_t), allocatable, save :: rn(:) |
| 100 |
integer, allocatable :: coreids(:) |
| 101 |
character(len=64) :: clpfx |
| 102 |
if (llfirst_time .and. .not. llnocomm) then |
| 103 |
allocate(coreids(0:maxth-1)) |
| 104 |
coreids(:) = -1 |
| 105 |
!$omp parallel num_threads(maxth) shared(coreids) private(i,myth,icoreid) |
| 106 |
do i=1,maxth |
| 107 |
icoreid = ec_coreid() |
| 108 |
myth = omp_get_thread_num() |
| 109 |
coreids(myth) = icoreid |
| 110 |
end do |
| 111 |
!$omp end parallel |
| 112 |
if (myproc == 0) then |
| 113 |
call slash_proc |
| 114 |
allocate(rn(0:nproc-1)) |
| 115 |
do i=0,nproc-1 |
| 116 |
rn(i)%nodenum = -1 |
| 117 |
if (i > 0) then |
| 118 |
call mpi_recv(lastnode, len(lastnode), mpi_byte, i, itag, kcomm, irecv_status, error) |
| 119 |
call check_error("from mpi_recv(lastnode)","/tmp/fiat/src/fiat/util/ec_meminfo.f90",258) |
| 120 |
call mpi_comm_rank(mpi_comm_world,k,error) |
| 121 |
rn(i)%rank = 0 |
| 122 |
rn(i)%str = cdstring |
| 123 |
rn(i)%pid = ec_getpid() |
| 124 |
end if |
| 125 |
rn(i)%rank_world = k |
| 126 |
rn(i)%iorank = iorank |
| 127 |
rn(i)%nodemaster = 0 |
| 128 |
call check_error("from mpi_send(iam_nodemaster)","/tmp/fiat/src/fiat/util/ec_meminfo.f90",305) |
| 129 |
end do |
| 130 |
call mpi_send(clstr,len(clstr),mpi_byte,0,itag+5,kcomm,error) |
| 131 |
call mpi_send(clstr,maxth,mpi_integer4,0,itag+6,kcomm,error) |
| 132 |
call mpi_recv(lastnode,1,mpi_integer4,0,itag+7,kcomm,irecv_status,error) |
| 133 |
end if |
| 134 |
end if |
| 135 |
contains |
| 136 |
subroutine slash_proc |
| 137 |
read(line(idx+iclkeylen-1:),*,err=99,end=98) node(:,0) |
| 138 |
98 continue |
| 139 |
do k=1,maxnuma-1 |
| 140 |
read(line(idx+iclkeylen-1:),*,err=99) node(0:n18-1,k) |
| 141 |
end do |
| 142 |
99 continue |
| 143 |
close(502) |
| 144 |
smallpage(:) = 0 |
| 145 |
do k=0,nnuma-1 |
| 146 |
do j=0,n18-1 |
| 147 |
end do |
| 148 |
smallpage(k) = sum(bucket(0:8,k))/onemega |
| 149 |
hugepage(k) = sum(bucket(9:n18-1,k))/onemega |
| 150 |
end do |
| 151 |
open(file="/proc/meminfo",unit=502,status="old",action="read",err=977) |
| 152 |
do i=1,10 |
| 153 |
read(502,'(a)',err=988,end=988) line |
| 154 |
if(line(1:7) == "memfree") then |
| 155 |
read(line(9:80),*) memfree |
| 156 |
else if(line(1:6) == "cached") then |
| 157 |
read(line(8:80),*) cached |
| 158 |
end if |
| 159 |
end do |
| 160 |
988 continue |
| 161 |
close(502) |
| 162 |
977 continue |
| 163 |
memfree=memfree/1024 |
| 164 |
end subroutine slash_proc |
| 165 |
subroutine prt_data(kun,knodenum,cdlastnode,kcall) |
| 166 |
character(len=4096) :: clbuf |
| 167 |
write(clbuf(ilen+1:),'(2x,2i8,3x,2f6.1,1x,i9,1x,i6,1x,a7,1x,a)') trim(id_string) |
| 168 |
end subroutine prt_data |
| 169 |
subroutine check_error(clwhat,srcfile,srcline) |
| 170 |
character(len=*), intent(in) :: clwhat, srcfile |
| 171 |
integer, intent(in) :: srcline |
| 172 |
if (error /= 0) then |
| 173 |
write(0,'(a,i0,1x,a,1x,"(",a,":",i0,")")') & |
| 174 |
& clpfx(1:ipfxlen)//"## ec_meminfo error code =",error,clwhat,srcfile,srcline |
| 175 |
call mpi_abort(kcomm,-1,error) |
| 176 |
end if |
| 177 |
end subroutine check_error |
| 178 |
subroutine rnsort(kun) |
| 179 |
do i=0,nproc-1 |
| 180 |
end do |
| 181 |
end subroutine rnsort |
| 182 |
end subroutine ec_meminfo |