test_parallel_temp_region.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/env bash
  2. # Test usage of temporary region in Python in parallel and when nested.
  3. # Even with the nesting the parallelization happens only on the first
  4. # level the nested processes don't create only one child.
  5. # Calls a Python script to do the actual job.
  6. # Script can be executed without parameters which is meant primarily for
  7. # automated testing.
  8. # See the command line parameters handling below for further details.
  9. # Undefined variables are errors.
  10. set -u
  11. # More set commands later on.
  12. if [ $# -eq 0 ]
  13. then
  14. # No arguments supplied, use default which is small enough to run
  15. # well on small machines and does not overwhelm a normal system.
  16. MAP_PARALLEL=parallel_tmp_region_parallel
  17. MAP_NEST=parallel_tmp_region_nest
  18. NUM_SEQUNTIALS=10
  19. NUM_PARALLELS=50
  20. SIMPLE_SIZE=150
  21. NEST_SIZES=100,200
  22. NUM_NEST=2
  23. elif [ $# -eq 7 ]
  24. then
  25. # Allow user to set a large number of processes.
  26. MAP_PARALLEL=$1
  27. MAP_NEST=$2
  28. NUM_SEQUNTIALS=$3
  29. NUM_PARALLELS=$4
  30. SIMPLE_SIZE=$5
  31. NEST_SIZES=$6
  32. NUM_NEST=$7
  33. else
  34. >&2 echo "Usage:"
  35. >&2 echo " $0"
  36. >&2 echo " $0 <par name> <nest name> <nproc seq> <nproc par> <simple size> <nest sizes> <num nest>"
  37. >&2 echo "Example:"
  38. >&2 echo " $0 parallel nest 5 50 250 100,200,300,400 4"
  39. >&2 echo "Notes:"
  40. >&2 echo " Runs are done in these combinations and order:"
  41. >&2 echo " Serial and simple (i.e., sequence, not nested)"
  42. >&2 echo " Parallel and simple (i.e., not nested)"
  43. >&2 echo " Serial and nested"
  44. >&2 echo " Parallel and nested"
  45. >&2 echo " The <num nest> should be number of elements in <nest sizes>."
  46. >&2 echo " Nesting numbering in output raster maps starts with 0."
  47. >&2 echo " Return codes are checked only for serial runs."
  48. >&2 echo " Raster maps are produced only for parallel runs."
  49. >&2 echo "Use zero or seven parameters, not $#."
  50. exit 1
  51. fi
  52. MAP_PARALLEL_PATTERN="${MAP_PARALLEL}_*_size_*_nesting_*"
  53. MAP_NEST_PATTERN="${MAP_NEST}_*_size_*_nesting_*"
  54. # Remove maps at exit.
  55. cleanup () {
  56. EXIT_CODE=$?
  57. g.remove type=raster pattern="${MAP_PARALLEL_PATTERN}" -f --quiet
  58. g.remove type=raster pattern="${MAP_NEST_PATTERN}" -f --quiet
  59. exit $EXIT_CODE
  60. }
  61. trap cleanup EXIT
  62. SCRIPT="./data/script_using_temporary_region.py"
  63. # First, test if the script is in its place.
  64. # (This needs to be tested explicitly because command_not_found_handle
  65. # implementations may return 0 when command/file is not found.)
  66. command -v "${SCRIPT}"
  67. if [ $? -ne 0 ]
  68. then
  69. >&2 echo "Script ${SCRIPT} not found"
  70. exit 1
  71. fi
  72. # Fail fast and show commands
  73. set -e
  74. set -x
  75. # Serial/Sequential
  76. for i in `seq 1 $NUM_SEQUNTIALS`
  77. do
  78. "${SCRIPT}" "${SIMPLE_SIZE}" 0
  79. done
  80. # Parallel
  81. # Because it is much harder to check return codes of parallel processes,
  82. # we go a step further and generate data and check their presence.
  83. for i in `seq 1 $NUM_PARALLELS`
  84. do
  85. "${SCRIPT}" "${SIMPLE_SIZE}" 0 "${MAP_PARALLEL}_$i" &
  86. done
  87. wait
  88. EXPECTED=$NUM_PARALLELS
  89. NUM=$(g.list type=raster pattern="${MAP_PARALLEL_PATTERN}" mapset=. | wc -l)
  90. if [ ${NUM} -ne ${EXPECTED} ]
  91. then
  92. echo "Pure parallel test: Got ${NUM} but expected ${EXPECTED} maps"
  93. exit 1
  94. fi
  95. # With nesting
  96. for i in `seq 1 $NUM_SEQUNTIALS`
  97. do
  98. "${SCRIPT}" "${NEST_SIZES}" 0
  99. done
  100. for i in `seq 1 $NUM_PARALLELS`
  101. do
  102. "${SCRIPT}" "${NEST_SIZES}" 0 "${MAP_NEST}_$i" &
  103. done
  104. wait
  105. EXPECTED=$(( $NUM_PARALLELS * $NUM_NEST ))
  106. NUM=$(g.list type=raster pattern="${MAP_NEST_PATTERN}" mapset=. | wc -l)
  107. if [ ${NUM} -ne ${EXPECTED} ]
  108. then
  109. echo "Parallel with nesting: Got ${NUM} but expected ${EXPECTED} maps"
  110. exit 1
  111. fi