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

Test random number sequence #60

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion ci_stub/onyx_job_test_cpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ env | grep JOB_COUNT

JOB_COUNT=1

cd ./KORC/build_cpu && ctest -j ${JOB_COUNT:-1} --output-on-failure
cd ./KORC/build_cpu && ctest -j --output-on-failure

2 changes: 1 addition & 1 deletion ci_stub/onyx_job_test_gpu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ JOB_COUNT=1

pushd ./KORC/build_gpu >/dev/null

ctest -j ${JOB_COUNT:-1} --output-on-failure
ctest -j --output-on-failure

pushd ./bin >/dev/null

Expand Down
12 changes: 6 additions & 6 deletions src/korc_ppusher.f90
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,13 @@ subroutine FO_init(params,F,spp,output,step)
eta_tmp=180.0_rp/C_PI* &
ACOS((B_X(cc)*V_X(cc)+B_Y(cc)*V_Y(cc)+B_Z(cc)*V_Z(cc))/(Bmag(cc)*v(cc)))

if ((eta_tmp.gt.20._rp).or. &
((spp(ii)%vars%eta(pp-1+cc)-eta_tmp)/spp(ii)%vars%eta(pp-1+cc).gt.0.01)) then
write(6,*) 'abberation',pp
write(6,*) pp,spp(ii)%vars%eta(pp-1+cc),eta_tmp,'B', &
spp(ii)%vars%B(pp-1+cc,:),'PSI_P',spp(ii)%vars%PSI_P(pp-1+cc)
!if ((eta_tmp.gt.20._rp).or. &
! ((spp(ii)%vars%eta(pp-1+cc)-eta_tmp)/spp(ii)%vars%eta(pp-1+cc).gt.0.01)) then
! write(6,*) 'abberation',pp
! write(6,*) pp,spp(ii)%vars%eta(pp-1+cc),eta_tmp,'B', &
! spp(ii)%vars%B(pp-1+cc,:),'PSI_P',spp(ii)%vars%PSI_P(pp-1+cc)

endif
!endif

spp(ii)%vars%eta(pp-1+cc) = eta_tmp

Expand Down
12 changes: 6 additions & 6 deletions src/korc_velocity_distribution.f90
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,12 @@ subroutine gyro_distribution(params,random,F,spp)
ALLOCATE( theta(spp%ppp) )

! * * * * INITIALIZE VELOCITY * * * *
if (.not.params%SameRandSeed) then
CALL random%uniform%set(0.0_rp,1.0_rp)
do pp=1_idef,spp%ppp
theta(pp)=random%uniform%get()
enddo
endif
!if (.not.params%SameRandSeed) then
CALL random%uniform%set(0.0_rp,1.0_rp)
do pp=1_idef,spp%ppp
theta(pp)=random%uniform%get()
enddo
!endif
theta = 2.0_rp*C_PI*theta

if (spp%spatial_distribution.eq.'TRACER') theta=2.0*C_PI
Expand Down
27 changes: 14 additions & 13 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target_sources(xtest
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/korc_test.f90>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test_io.f90>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test_hpc.f90>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/test_random.f90>
)
target_link_libraries (xtest

Expand All @@ -22,29 +23,29 @@ set_property(TARGET xtest PROPERTY LINKER_LANGUAGE Fortran)
configure_file(${CMAKE_SOURCE_DIR}/test/egyro/korc_egyro.sh.in ${CMAKE_BINARY_DIR}/egyro_test/korc_egyro.sh)
configure_file(${CMAKE_SOURCE_DIR}/test/mars/korc_mars.sh.in ${CMAKE_BINARY_DIR}/mars_test/korc_mars.sh)

if(USE_PSPLINE)
add_test (NAME mars_test_1
COMMAND ${CMAKE_BINARY_DIR}/mars_test/korc_mars.sh 1
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_tests_properties (mars_test_1 PROPERTIES PROCESSORS 1 ENVIRONMENT OMP_NUM_THREADS=1)
endif()
#if(USE_PSPLINE)
# add_test (NAME mars_test_1
# COMMAND ${CMAKE_BINARY_DIR}/mars_test/korc_mars.sh 1
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# set_tests_properties (mars_test_1 PROPERTIES PROCESSORS 1 ENVIRONMENT OMP_NUM_THREADS=1)
#endif()

file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/egyro_test)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin/mars_test)

foreach(RANK IN ITEMS 1 2 4 8 16)
foreach(RANK IN ITEMS 1 2 4 8) #16)
if(${RANK} LESS_EQUAL ${MPIEXEC_MAX_NUMPROCS})
add_test (NAME egyro_test_${RANK}
COMMAND ${CMAKE_BINARY_DIR}/egyro_test/korc_egyro.sh ${RANK}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_tests_properties (egyro_test_${RANK} PROPERTIES PROCESSORS ${RANK} ENVIRONMENT OMP_NUM_THREADS=1)

# if(USE_PSPLINE)
# add_test (NAME mars_test_${RANK}
# COMMAND ${CMAKE_BINARY_DIR}/mars_test/korc_mars.sh ${RANK}
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# set_tests_properties (mars_test_${RANK} PROPERTIES PROCESSORS ${RANK} ENVIRONMENT OMP_NUM_THREADS=1)
# endif()
if(USE_PSPLINE)
add_test (NAME mars_test_${RANK}
COMMAND ${CMAKE_BINARY_DIR}/mars_test/korc_mars.sh ${RANK}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_tests_properties (mars_test_${RANK} PROPERTIES PROCESSORS ${RANK} ENVIRONMENT OMP_NUM_THREADS=1)
endif()

add_test (NAME unit_testing_${RANK}
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${RANK} ./xtest TEST_OUT
Expand Down
12 changes: 10 additions & 2 deletions test/korc_test.f90
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ program korc_test
use fruit
use test_io
use test_hpc
use test_random
use korc_hpc, only : initialize_mpi,finalize_mpi
implicit none
logical ok

TYPE(KORC_PARAMS) :: params
CHARACTER(MX_STRING_LENGTH) :: path_to_outputs

params%path_to_inputs='TEST'
call initialize_mpi(params)

! create output file for testing
call set_paths(path_to_outputs)

Expand All @@ -15,7 +21,8 @@ program korc_test

! run tests
write(test_unit_write,*) 'Testing MPI initialization...'
call test_mpi_initialization
call test_mpi_initialization(params)
call test_random_auto

! compile summary and finalize fruit
call fruit_summary(test_unit_write)
Expand All @@ -29,5 +36,6 @@ program korc_test

close(test_unit_write)


call finalize_mpi(params)

end program korc_test
Binary file modified test/mars/file_0.h5
Binary file not shown.
Binary file added test/mars/file_0_1.h5
Binary file not shown.
Binary file added test/mars/file_0_2.h5
Binary file not shown.
Binary file added test/mars/file_0_4.h5
Binary file not shown.
Binary file added test/mars/file_0_8.h5
Binary file not shown.
Binary file removed test/mars/file_0_new_random.h5
Binary file not shown.
4 changes: 2 additions & 2 deletions test/mars/input_file_D3D_191366_1762ms_MARS.korc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
! Append simulation results after previous simulation_time reached
reinit = F
! Begin a new simulation, reinitializing from restart file state
simulation_time = 1.E-7
simulation_time = 1.E-8
! Total aimed simulation time in seconds
! Run 10 mu s If transients exist put 5 extra mu s.
snapshot_frequency = 1.E-8
snapshot_frequency = 1.E-9
! Time between snapshots in seconds
restart_overwrite_frequency = 1.E-1
! Time between overwritting of restart file in seconds
Expand Down
2 changes: 1 addition & 1 deletion test/mars/korc_mars.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ fi

${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} $1 ./xkorc $INPUT_FILE $OUT_DIR/

h5diff -r -p 0.000008 $OUT_DIR/file_0.h5 ${CMAKE_SOURCE_DIR}/test/mars/file_0_new_random.h5
h5diff -r -p 0.000008 $OUT_DIR/file_0.h5 ${CMAKE_SOURCE_DIR}/test/mars/file_0_$1.h5
11 changes: 2 additions & 9 deletions test/test_hpc.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ module test_hpc

contains

subroutine test_mpi_initialization
use korc_hpc, only : initialize_mpi,finalize_mpi
TYPE(KORC_PARAMS) :: params
subroutine test_mpi_initialization(params)
TYPE(KORC_PARAMS), INTENT(INOUT) :: params
integer :: ierror
integer :: size, rank
integer :: size_k, rank_k

params%path_to_inputs='TEST'

call initialize_mpi(params)

size_k=params%mpi_params%nmpi
rank_k=params%mpi_params%rank

Expand All @@ -25,8 +20,6 @@ subroutine test_mpi_initialization

call assert_equals(size_k,size)
call assert_equals(rank_k,rank)

call finalize_mpi(params)

end subroutine test_mpi_initialization

Expand Down
101 changes: 101 additions & 0 deletions test/test_random.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
module test_random
use korc_random
use mpi
use fruit
implicit none

contains

SUBROUTINE test_random_auto
IMPLICIT NONE

! Local Variables
CLASS (random_U_context), POINTER :: uniform => null()
INTEGER :: mpierr
INTEGER :: i
INTEGER :: rank
INTEGER :: size
INTEGER :: localsize
REAL(rp), DIMENSION(:), ALLOCATABLE :: buffer
INTEGER, DIMENSION(:), ALLOCATABLE :: counts
INTEGER, DIMENSION(:), ALLOCATABLE :: offsets
REAL(rp) :: base
REAL(rp) :: test

! Local parameters
INTEGER, PARAMETER :: totalsize = 10000
INTEGER, PARAMETER :: window = totalsize/2

! Start of executable code.
call MPI_COMM_SIZE(MPI_COMM_WORLD, size, mpierr)
call MPI_COMM_RANK(MPI_COMM_WORLD, rank, mpierr)

IF (rank .eq. 0) THEN
WRITE (*,*)
WRITE (*,*) "Starting Random Test"
END IF

uniform => random_U_context_construct(0, rank)
CALL uniform%set(-1.0d0, 1.0d0)

localsize = totalsize/size
IF (rank .lt. MOD(totalsize, size)) THEN
localsize = localsize + 1
ENDIF

IF (rank .eq. 0) THEN
ALLOCATE(buffer(totalsize))
ALLOCATE(counts(size))
ALLOCATE(offsets(size))
CALL uniform%get_array(buffer(1:localsize))
ELSE
ALLOCATE(buffer(localsize))
CALL uniform%get_array(buffer)
END IF

CALL MPI_GATHER(localsize, 1, MPI_INTEGER, &
counts, 1, MPI_INTEGER, &
0, MPI_COMM_WORLD, mpierr)
IF (rank .eq. 0) THEN
offsets(1) = 0
DO i = 2, size
offsets(i) = offsets(i - 1)+counts(i - 1)
END DO
END IF
CALL MPI_GATHERV(buffer, localsize, MPI_DOUBLE, &
buffer, counts, offsets, MPI_DOUBLE, &
0, MPI_COMM_WORLD, mpierr)

IF (rank .eq. 0) THEN
DEALLOCATE(counts)
DEALLOCATE(offsets)

! Check against 10% of the first peak. We could go lower but I don't want to
! trigger a test failure on noise.
base = autocorrelation(buffer, 0)*0.1
DO i = 1, window
test = autocorrelation(buffer, i)
CALL assert_equals(test .gt. base, .false.)
END DO
END IF

DEALLOCATE(buffer)

END SUBROUTINE

FUNCTION autocorrelation(sequence, offset)

IMPLICIT NONE

! Declare arguments.
REAL(rp) :: autocorrelation
REAL(rp), DIMENSION(:) :: sequence
INTEGER :: offset

! Start of executable code.
autocorrelation = DOT_PRODUCT(sequence(:SIZE(sequence) - offset), &
sequence(offset + 1:)) &
/ (SIZE(sequence) - offset)
END FUNCTION

end module
Loading