Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid oversized arrays in scaling tests #214

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 54 additions & 18 deletions tests/scaling.f90
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ subroutine test_auction_sym_random
write(*, "(a)") "Testing auction_scaling_sym() with random matrices"
write(*, "(a)") "=================================================="

allocate(a%ptr(maxn+1))
allocate(a%row(2*maxnz), a%val(2*maxnz))
allocate(scaling(maxn), match(maxn), rmax(maxn), cnt(maxn))
! dummy allocations to simplify reallocating specific test case size in loop
allocate(a%ptr(0))
allocate(a%row(0), a%val(0))
allocate(scaling(0), match(0), rmax(0), cnt(0))

prblm_loop: &
do prblm = 1, nprob
Expand All @@ -88,6 +89,11 @@ subroutine test_auction_sym_random
cycle
endif

deallocate(a%ptr, a%row, a%val, scaling, match, rmax, cnt)
allocate(a%ptr(a%n+1))
allocate(a%row(nza), a%val(nza))
allocate(scaling(a%n), match(a%n), rmax(a%n), cnt(a%n))

call gen_random_sym(a, nza, state)
!print *, "n = ", a%n
!do i = 1, a%n
Expand Down Expand Up @@ -212,9 +218,10 @@ subroutine test_auction_unsym_random
write(*, "(a)") "Testing auction_scaling_unsym() with random matrices"
write(*, "(a)") "===================================================="

allocate(a%ptr(maxn+1))
allocate(a%row(2*maxnz), a%val(2*maxnz))
allocate(rscaling(maxn), cscaling(maxn), match(maxn), rmax(maxn), cnt(maxn))
! dummy allocations to simplify reallocating specific test case size in loop
allocate(a%ptr(0))
allocate(a%row(0), a%val(0))
allocate(rscaling(0), cscaling(0), match(0), rmax(0), cnt(0))

prblm_loop: &
do prblm = 1, nprob
Expand All @@ -241,6 +248,11 @@ subroutine test_auction_unsym_random
! cycle
!endif

deallocate(a%ptr, a%row, a%val, rscaling, cscaling, match, rmax, cnt)
allocate(a%ptr(a%n+1))
allocate(a%row(nza), a%val(nza))
allocate(rscaling(a%m), cscaling(a%n), match(a%m), rmax(a%m), cnt(a%n))

call gen_random_unsym(a, nza, state)
!print *, "n = ", a%n
!do i = 1, a%n
Expand Down Expand Up @@ -388,9 +400,10 @@ subroutine test_equilib_sym_random
write(*, "(a)") "Testing equilib_scaling_sym() with random matrices"
write(*, "(a)") "=================================================="

allocate(a%ptr(maxn+1))
allocate(a%row(2*maxnz), a%val(2*maxnz))
allocate(scaling(maxn), rinf(maxn))
! dummy allocations to simplify reallocating specific test case size in loop
allocate(a%ptr(0))
allocate(a%row(0), a%val(0))
allocate(scaling(0), rinf(0))

prblm_loop: &
do prblm = 1, nprob
Expand All @@ -412,6 +425,11 @@ subroutine test_equilib_sym_random
cycle
endif

deallocate(a%ptr, a%row, a%val, scaling, rinf)
allocate(a%ptr(a%n+1))
allocate(a%row(nza), a%val(nza))
allocate(scaling(a%n), rinf(a%n))

call gen_random_sym(a, nza, state)
!print *, "n = ", a%n
!do i = 1, a%n
Expand Down Expand Up @@ -480,9 +498,10 @@ subroutine test_equilib_unsym_random
write(*, "(a)") "Testing equilib_scaling_unsym() with random matrices"
write(*, "(a)") "===================================================="

allocate(a%ptr(maxn+1))
allocate(a%row(2*maxnz), a%val(2*maxnz))
allocate(rscaling(maxn), cscaling(maxn), rinf(maxn))
! dummy allocations to simplify reallocating specific test case size in loop
allocate(a%ptr(0))
allocate(a%row(0), a%val(0))
allocate(rscaling(0), cscaling(0), rinf(0))

prblm_loop: &
do prblm = 1, nprob
Expand Down Expand Up @@ -510,6 +529,11 @@ subroutine test_equilib_unsym_random
cycle
endif

deallocate(a%ptr, a%row, a%val, rscaling, cscaling, rinf)
allocate(a%ptr(a%n+1))
allocate(a%row(nza), a%val(nza))
allocate(rscaling(a%m), cscaling(a%n), rinf(a%m))

call gen_random_unsym(a, nza, state)
!print *, "n = ", a%n
!do i = 1, a%n
Expand Down Expand Up @@ -594,9 +618,10 @@ subroutine test_hungarian_sym_random
write(*, "(a)") "Testing hungarian_scaling_sym() with random matrices"
write(*, "(a)") "==================================================="

allocate(a%ptr(maxn+1))
allocate(a%row(2*maxnz), a%val(2*maxnz))
allocate(scaling(maxn), match(maxn), rmax(maxn), cnt(maxn))
! dummy allocations to simplify reallocating specific test case size in loop
allocate(a%ptr(0))
allocate(a%row(0), a%val(0))
allocate(scaling(0), match(0), rmax(0), cnt(0))

prblm_loop: &
do prblm = 1, nprob
Expand All @@ -618,6 +643,11 @@ subroutine test_hungarian_sym_random
cycle
endif

deallocate(a%ptr, a%row, a%val, scaling, match, rmax, cnt)
allocate(a%ptr(a%n+1))
allocate(a%row(nza), a%val(nza))
allocate(scaling(a%n), match(a%n), rmax(a%n), cnt(a%n))

call gen_random_sym(a, nza, state)
!print *, "n = ", a%n
!do i = 1, a%n
Expand Down Expand Up @@ -726,9 +756,10 @@ subroutine test_hungarian_unsym_random
write(*, "(a)") "Testing hungarian_scaling_unsym() with random matrices"
write(*, "(a)") "======================================================"

allocate(a%ptr(maxn+1))
allocate(a%row(2*maxnz), a%val(2*maxnz))
allocate(rscaling(maxn), cscaling(maxn), match(maxn), rmax(maxn), cnt(maxn))
! dummy allocations to simplify reallocating specific test case size in loop
allocate(a%ptr(0))
allocate(a%row(0), a%val(0))
allocate(rscaling(0), cscaling(0), match(0), rmax(0), cnt(0))

prblm_loop: &
do prblm = 1, nprob
Expand All @@ -748,6 +779,11 @@ subroutine test_hungarian_unsym_random
write(*, "(a, i3, a, i5, a, i5, a, i7, a, i2, a)",advance="no") &
" - no. ", prblm, " m = ", a%m, " n = ", a%n, " nza = ", nza, "..."

deallocate(a%ptr, a%row, a%val, rscaling, cscaling, match, rmax, cnt)
allocate(a%ptr(a%n+1))
allocate(a%row(nza), a%val(nza))
allocate(rscaling(a%m), cscaling(a%n), match(a%m), rmax(a%m), cnt(a%n))

if(nza.gt.maxnz .or. a%n.gt.maxn .or. a%m.gt.maxn) then
write(*, "(a)") "bad random matrix."
write(*, "(a,i5,a,i5,a,i5)") "m = ", a%m, "n = ", a%n, &
Expand Down
Loading