#!/bin/sh -- # Three lines of sillyness, in case the location of wish varies
eval 'exec cat tcg | tail +4 | wish -name "PVM Distributed Solvers"'
exit 0
#
# A Tcl/Tk/Wish based interface to the
# Distributed Iterative Linear System Solvers
#
# (c) Victor Eijkhout 1994

# surrounding frames for groups of buttons
proc newframe {f t } {global thisframe
	frame .$f -relief groove -bd 4
	label .t$f -text $t
	pack .t$f .$f -side top -anchor w
	set thisframe $f}
proc sframe f {global thisframe
	frame .$f -relief groove -bd 4
	pack .$f -side top -anchor w
	set thisframe $f}
proc newrow r {global thisframe
	frame .$r
	pack .$r -in .$thisframe -side top -anchor w}

newframe proc_grid "Processor structure"
	newrow procs
newframe problem_def "Problem definition"
	newrow formats ; newrow sym_storage ; newrow pde
newframe iter_meth "Iterative method"
	newrow methods ; newrow iters ; newrow itpars ; newrow stops
newframe precond "Preconditioner"
	newrow precs ; newrow precparms
newframe trace_def "Trace modes"
	newrow traces ; newrow dumps ; newrow coms
sframe log
sframe master_control ; newrow bottom

# log messages
text .logmsgs -relief sunken -bd 2 -yscrollcommand ".scroll set"
scrollbar .scroll -command ".logmsgs yview"
pack .logmsgs -in .log -side left
pack .scroll -in .log -side right -fill y
proc log msg {.text insert end $msg}
proc do comm {set x [concat {exec -keepnewline} $comm ]
	.logmsgs insert end [eval $x]}

# processor organisation
label .l1 -text "Processors:"
set psize1 1
entry .proc1 -width 4 -relief sunken -textvariable psize1

label .l2 -text "by"
set psize2 1
entry .proc2 -width 4 -relief sunken -textvariable psize2

bind .proc1 <Return> {set x {./proc_grid}
	set x [lappend x $psize1]
	set x [lappend x $psize2]
	do $x}
bind .proc2 <Return> {set x {./proc_grid}
	set x [lappend x $psize1]
	set x [lappend x $psize2]
	do $x}

label .l3 -text "grid.  Reader:"
radiobutton .one_reader -text "one" -variable reader -value 1 \
	-command "do {./one_read}"
radiobutton .all_reader -text "all" -variable reader -value 0 \
	-command "do {./all_read}"
set reader 0
do {./proc_grid 1 1} ; do {./all_read}
pack .l1 .proc1 .l2 .proc2 \
	.l3 .one_reader .all_reader \
	-in .procs -side left


#
# matrix format, basic & options
#
# basic matrix format
set mattyp gridi
exec /bin/rm -f fmt.dat 
exec /bin/touch fmt.dat 
do {./unit_rhs.bat} ; do {./mat_int.bat} ; do {./mat_grid.bat}
radiobutton .matgridi -text "Grid (int)" \
	-variable mattyp -value gridi \
	-command "do {./mat_int.bat} ; do {./mat_grid.bat}"
radiobutton .matgride -text "Grid (ext)" -variable mattyp -value gride \
	-command "do {./mat_ext.bat} ; do {./mat_grid.bat}"
radiobutton .matdiag -text "Diagonal" -variable mattyp -value diag \
	-command "do {./mat_ext.bat} ; do {./mat_diag.bat}"
radiobutton .matcprs -text "Compress" -variable mattyp -value cprs \
	-command "do {./mat_ext.bat} ; do {./mat_cprs.bat}"
label .l5 -text "Matrix format:"
pack .l5 .matgridi .matgride .matdiag .matcprs \
	-in .formats -side left
# format options
set sym_store no
do {./store_unsymm.bat}
label .l25 -text "Storage:"
radiobutton .sym_format -text Symmetric -variable sym_store -value yes \
	-command "do {./store_symm.bat}"
radiobutton .unsym_format -text Unsymmetric -variable sym_store -value no \
	-command "do {./store_unsymm.bat}"
set part_scheme 1
do {./part_zilch.bat}
label .l27 -text "Partitioning:"
radiobutton .part_consec -text Consecutive -variable part_scheme -value 0 \
	-command "do {./part_consec.bat}"
radiobutton .part_zilch -text Arbitary -variable part_scheme -value 1 \
	-command "do {./part_zilch.bat}"
pack \
	.l25 .sym_format .unsym_format \
	-in .sym_storage -side left
#	.l27 .part_consec .part_zilch \

#
# PDE
#
label .l6 -text "PDE; domain size:"
set domi 8
set domj 8
entry .domaini	-width 6 -relief sunken -textvariable domi
entry .domainj	-width 6 -relief sunken -textvariable domj
bind .domaini <Return> {set x {./size}
	set x [lappend x $domi]
	set x [lappend x $domj]
	do $x}
bind .domainj <Return> {set x {./size}
	set x [lappend x $domi]
	set x [lappend x $domj]
	do $x}
label .l7 -text "Indefinitess:"
set indef 0.0
entry .indef	-width 6 -relief sunken -textvariable indef
bind .indef <Return> {set x {./indef}
	set x [lappend x $indef]
	do $x}
label .l8 -text "Unsymmetry:"
set unsym 0.0
entry .unsym	-width 6 -relief sunken -textvariable unsym
bind .unsym <Return> {set x {./unsym}
	set x [lappend x $unsym]
	do $x}
pack .l6 .domaini .domainj .l7 .indef .l8 .unsym -in .pde -side left
do {./size 8 8} ; do {./fish}

# generate the methods radio buttons
set methods {cg cgne minres nscg gmres bicg qmr cgs bcgs}
set method cg
exec /bin/rm -f itr.dat 
exec /bin/touch itr.dat
do {./cg.bat}
label .l4 -text "Iterative method:"
foreach m $methods {lappend dotmethods .$m}
foreach m $methods {
	radiobutton .$m -text $m \
		-variable method	-value $m \
		-command "do {./$m.bat}"
	}

label .l29 -text "MGS:"
set mgs 0
radiobutton .nomgs -text "No" \
	-variable mgs -value 0 \
	-command "do {./mod_gs.bat 0}"
radiobutton .bitmgs -text "Bit" \
	-variable mgs -value 1 \
	-command "do {./mod_gs.bat 1}"
radiobutton .yesmgs -text "Yes" \
	-variable mgs -value 2 \
	-command "do {./mod_gs.bat 2}"

set x  [concat {pack .l4} $dotmethods \
	{-in .methods -side left}]
eval $x

# iteration parameters
label .l18 -text "Truncate:"
set trunc 25
do {./trunc.bat 25}
entry .trunc -width 4 -relief sunken -textvariable trunc
bind .trunc <Return> {set x {./trunc.bat}
	set x [lappend x $trunc]
	do $x}

label .l19 -text "Max iterations:"
set maxit 100
do {./max_iter.bat 100}
entry .maxit -width 5 -relief sunken -textvariable maxit
bind .maxit <Return> {set x {./max_iter.bat}
	set x [lappend x $maxit]
	do $x}

label .l20 -text "Reduction:"
set reduc .0001
do {./tolerance.bat .0001}
entry .reduc -width 10 -relief sunken -textvariable reduc
bind .reduc <Return> {set x {./tolerance.bat}
	set x [lappend x $reduc]
	do $x}

label .l30 -text "Restart"
set rstart 0
entry .rstart -width 4 -relief sunken -textvariable rstart
bind .rstart <Return> {set x {./restart.bat}
	set x [lappend x $rstart]
	do $x}

pack .l18 .trunc .l19 .maxit .l20 .reduc \
	.l30 .rstart \
	-in .itpars -side left

# stopping tests
label .l21 -text "Stopping test"
set stoptest sure
do {./sure_stop.bat}
radiobutton .stopabs -text "Absolute" -variable stoptest -value abs \
	-command "do {./abs_stop.bat}"
radiobutton .stoprel -text "Relative" -variable stoptest -value rel \
	-command "do {./rel_stop.bat}"
radiobutton .stoprhs -text "RHS" -variable stoptest -value rhs \
	-command "do {./rhs_stop.bat}"
radiobutton .stopsure -text "|A| |x| + |b|" -variable stoptest -value sure \
	-command "do {./sure_stop.bat}"
label .l24 -text "History"
set ithist no
radiobutton .itnohist -variable ithist -value no -text "No" \
	-command "do {./trace_stats.bat 0}"
radiobutton .itpophist -variable ithist -value pop -text "Popup" \
	-command "do {./trace_stats.bat 2}"
pack .l21 .stopabs .stoprel .stoprhs .stopsure \
	.l24 .itnohist .itpophist \
	-in .stops -side left

# preconditioner
exec /bin/rm -f prc.dat
exec /bin/touch prc.dat
set prec none
do {./prec_none.bat}
radiobutton .prec_none -variable prec -value none \
	-command "do {./prec_none.bat}" \
	-text "None"
radiobutton .prec_full_jacobi -variable prec -value full_jacobi \
	-command "do {./prec_full_jacobi.bat}" \
	-text "Jacobi"
radiobutton .prec_ssor_jacobi -variable prec -value ssor_jacobi \
	-command "do {./prec_ssor_jacobi.bat}" \
	-text "SSOR/J"
radiobutton .prec_ilu_jacobi -variable prec -value ilu_jacobi \
	-command "do {./prec_ilu_jacobi.bat}" \
	-text "ILU/J"
radiobutton .prec_full_ssor -variable prec -value full_ssor \
	-command "do {./prec_full_ssor.bat}" \
	-text "SSOR"
radiobutton .prec_full_ilu -variable prec -value full_ilu \
	-command "do {./prec_full_ilu.bat}" \
	-text "ILU"
radiobutton .prec_par_ssor -variable prec -value par_ssor \
	-command "do {./prec_par_ssor.bat}" \
	-text "SSOR (mc)"
radiobutton .prec_par_ilu -variable prec -value par_ilu \
	-command "do {./prec_par_ilu.bat}" \
	-text "ILU (mc)"
radiobutton .prec_test -variable prec -value test \
	-command "do {./prec_test.bat}" \
	-text "Test"
pack .prec_none .prec_full_jacobi \
	.prec_ssor_jacobi .prec_ilu_jacobi \
	.prec_full_ssor .prec_full_ilu \
	.prec_par_ssor .prec_par_ilu \
	.prec_test \
	-in .precs -side left
label .l26 -text "Neumann expansion:"
set xterms 0
entry .neu_expand -width 3 -relief sunken -textvariable xterms
bind .neu_expand <Return> {set x {./prec_neu.bat}
	set x [lappend x $xterms]
	do $x}
pack .l26 .neu_expand -in .precparms -side left

# generate heaps of trace buttons
do { ./def_trace}
label .l9 -text "Trace output:"
set traceout screen
radiobutton .traces.screen -text "to Screen" \
	-variable traceout -value screen \
	-command "do {./trace_screen.bat 0}"
radiobutton .traces.file -text "to File" \
	-variable traceout -value file \
	-command "do {./trace_screen.bat 2}"
label .l10 -text "Keep log file:"
set logfile yes
do { ./trace_log-file.bat 1}
radiobutton .nolog -text "No" \
	-variable logfile -value no \
	-command "do {./trace_log-file.bat 0}"
radiobutton .yeslog -text "Yes" \
	-variable logfile -value yes \
	-command "do {./trace_log-file.bat 1}"
label .l28 -text "Debug run:"
set dbx no
radiobutton .nodbx -text "No" \
	-variable dbx -value no \
	-command "do {./dbx.bat 0}"
radiobutton .yesdbx -text "Yes" \
	-variable dbx -value yes \
	-command "do {./dbx.bat 1}"
pack	.l9 .traces.screen .traces.file \
	.l10 .nolog .yeslog .l28 .nodbx .yesdbx \
	-in .traces -side left

# dump modes
label .l11 -text "Dump matrix"
set matdmp no
radiobutton .nomatdmp -text "No" -variable matdmp -value no \
	-command "do {./trace_matrix-dump.bat 0}"
radiobutton .yesmatdmp -text "Yes" -variable matdmp -value yes \
	-command "do {./trace_matrix-dump.bat 1}"
label .l13 -text "Allocation"
set alcdmp no
radiobutton .noalcdmp -text "No" -variable alcdmp -value no \
	-command "do {./trace_allocation.bat 0}"
radiobutton .yesalcdmp -text "Yes" -variable alcdmp -value yes \
	-command "do {./trace_allocation.bat 1}"
label .l14 -text "File IO"
set iodmp no
radiobutton .noiodmp -text "No" -variable iodmp -value no \
	-command "do {./trace_fileio.bat 0}"
radiobutton .yesiodmp -text "Yes" -variable iodmp -value yes \
	-command "do {./trace_fileio.bat 1}"
label .l15 -text "Setup"
set setupdmp no
radiobutton .nosetupdmp -text "No" -variable setupdmp -value no \
	-command "do {./trace_setup.bat 0}"
radiobutton .yessetupdmp -text "Yes" -variable setupdmp -value yes \
	-command "do {./trace_setup.bat 1}"
pack 	.l11 .nomatdmp .yesmatdmp \
	.l13 .noalcdmp .yesalcdmp .l14 .noiodmp .yesiodmp \
	.l15 .nosetupdmp .yessetupdmp \
	-in .dumps -side left

# iteration trace
set ittrace error
do {./trace_iteration.bat 1}
label .l16 -text "Iteration trace"
radiobutton .itsilent -text "Silent" -variable ittrace -value silent \
	-command "do {./trace_iteration.bat 0}"
radiobutton .iterror -text "Error" -variable ittrace -value error \
	-command "do {./trace_iteration.bat 1}"
radiobutton .itprogress -text "Progress" -variable ittrace -value progress \
	-command "do {./trace_iteration.bat 2}"
radiobutton .itscalars -text "Scalars" -variable ittrace -value scalars \
	-command "do {./trace_iteration.bat 3}"
radiobutton .itvectors -text "Vectors" -variable ittrace -value vectors \
	-command "do {./trace_iteration.bat 4}"
pack	.l16 .itsilent .iterror .itprogress .itscalars .itvectors \
	.l29 .nomgs .bitmgs .yesmgs \
	-in .iters -side left

# communication dump, memory tests
label .l12 -text "Communication"
set comdmp no
radiobutton .nocomdmp -text "No" -variable comdmp -value no \
	-command "do {./trace_communication.bat 0}"
radiobutton .yescomdmp -text "Msg ids" -variable comdmp -value yes \
	-command "do {./trace_communication.bat 1}"
radiobutton .fullcomdmp -text "Contents" -variable comdmp -value full \
	-command "do {./trace_communication.bat 2}"
label .l17 -text "Memory tests"
set memtest no
do { ./trace_memtest.bat 0}
radiobutton .nomemtest -text "No" -variable memtest -value no \
	-command "do {./trace_memtest.bat 0}"
radiobutton .yesmemtest -text "Per iter" -variable memtest -value yes \
	-command "do {./trace_memtest.bat 1}"
radiobutton .fullmemtest -text "Full" -variable memtest -value full \
	-command "do {./trace_memtest.bat 2}"
pack	.l12 .nocomdmp .yescomdmp .fullcomdmp \
	.l17 .nomemtest .yesmemtest .fullmemtest \
	-in .coms -side left

# bottom line
button .run -text "Start Iteration" \
	-command "exec ../cg_run &"
button .matgen -text "Generate Matrix" \
	-command "exec ./make_extmat &"
button .popup -text "Popup" \
	-command "exec xgraph ../local.data/grdhst.xg &"
button .quit -text "Exit Interface" \
	-command exit
pack .run .matgen .popup .quit -in .bottom -side left
frame .coco -relief groove 
pack .coco -in .bottom -side right
label .l23 -text "Victor Eijkhout (c) 1994"
pack .l23 -in .coco
pack configure .master_control	-expand true -fill x
pack configure .bottom		-expand true -fill x

# label count: 30
