[Dart-dev] DART/branches Revision: 13211

dart at ucar.edu dart at ucar.edu
Wed Jul 31 08:56:01 MDT 2019


nancy at ucar.edu
2019-07-31 08:56:01 -0600 (Wed, 31 Jul 2019)
270
add the start of a test for our sort routines.
for sorts there are two things to test - that it gives
the correct results, and that it is fast.  so there are
some starts of timing routines in this test as well.

it isn't finished by a long shot - this is just a start.




Added: DART/branches/rma_trunk/developer_tests/utilities/sort_test.f90
===================================================================
--- DART/branches/rma_trunk/developer_tests/utilities/sort_test.f90	                        (rev 0)
+++ DART/branches/rma_trunk/developer_tests/utilities/sort_test.f90	2019-07-31 14:56:01 UTC (rev 13211)
@@ -0,0 +1,198 @@
+! DART software - Copyright UCAR. This open source software is provided
+! by UCAR, "as is", without charge, subject to all terms of use at
+! http://www.image.ucar.edu/DAReS/DART/DART_download
+!
+! $Id: model_mod.f90 12563 2018-04-26 21:34:00Z nancy at ucar.edu $
+
+! test of the various sort routines in the utilities module.
+!
+! things to add: 
+!  repeat the sorts (w/ different but reproducible data?) and time them
+!  do the sorts on lists of different lengths.
+!  output stats
+
+program sort_test
+
+use types_mod, only : r8, digits12
+use utilities_mod, only : error_handler, E_MSG, E_ERR
+!use sort_mod, only : sort, index_sort, simple_sort
+use sort_mod, only : simple_sort, simple_index_sort, sort, index_sort, insertion_sort, index_insertion_sort
+use random_seq_mod, only: random_seq_type, init_random_seq, random_gaussian
+use mpi_utilities_mod, only : start_mpi_timer, read_mpi_timer
+
+!> usage:
+!>  real(digits12) :: base, time_elapsed
+!>
+!>  call start_mpi_timer(base)
+!>  time_elapsed = read_mpi_timer(base)
+
+
+integer, parameter :: MAXSIZE = 25000
+integer, parameter :: SAMPLE = 10
+type(random_seq_type) :: seq
+
+real(r8), parameter :: BASEVAL = 25.0_r8
+real(r8), parameter :: STDDEV = 5.0_r8
+
+real(r8) :: array1(MAXSIZE), array2(MAXSIZE)
+real(r8) :: sorted1(MAXSIZE), sorted2(MAXSIZE)
+integer  :: indirect1(MAXSIZE), indirect2(MAXSIZE)
+
+integer  :: i
+real(digits12) :: b(10), inc
+real(r8) :: fract, thisval, thesevals(MAXSIZE), tmp
+character(len=512) :: string1
+
+character(len=*), parameter :: routine = 'sort_test'
+
+! fill the array with random values for sorting.
+
+call init_random_seq(seq)
+
+do i=1, MAXSIZE
+   array1(i) = random_gaussian(seq, BASEVAL, STDDEV)
+enddo
+
+
+write(*,*) ""
+write(*,*) "random"
+
+call start_mpi_timer(b(1))
+sorted1 = sort(array1)
+inc = read_mpi_timer(b(1))
+call print_time(inc, 'basic sort')
+
+call start_mpi_timer(b(2))
+call index_sort(array1, indirect1, MAXSIZE)
+inc = read_mpi_timer(b(2))
+call print_time(inc, 'index sort')
+
+
+sorted1 = array1
+call start_mpi_timer(b(1))
+call insertion_sort(array1)
+inc = read_mpi_timer(b(1))
+call print_time(inc, 'insertion sort')
+
+call start_mpi_timer(b(2))
+call index_insertion_sort(array1, indirect1, MAXSIZE)
+inc = read_mpi_timer(b(2))
+call print_time(inc, 'index insertion sort')
+
+write(*,*) ""
+write(*,*) "inverted order"
+
+! inverted order arrays
+do i=1, MAXSIZE
+   array2(i) = array1(MAXSIZE - i + 1)
+enddo
+
+do i=1, MAXSIZE
+   sorted2(i) = sorted1(MAXSIZE - i + 1)
+enddo
+
+
+call start_mpi_timer(b(1))
+sorted2 = sort(array2)


More information about the Dart-dev mailing list