MODULE System_Monitors USE Precision USE Standard_Types,ONLY:BIT_SIZE USE StopWatch USE Error_Handling IMPLICIT NONE PUBLIC::CreateMonitors,DestroyMonitors,StartTimer,StopTimer,ResetTimer,ReadTimer,& RecordAllocation,MemoryUsage PRIVATE INTEGER,PARAMETER,PUBLIC::n_timers=100 TYPE(WATCHTYPE),DIMENSION(n_timers),PUBLIC::timers INTEGER(KIND=i_dp),PUBLIC,SAVE::n_flops=0,n_reads=0,n_writes=0 INTEGER(KIND=i_dp),PUBLIC,SAVE::allocated_memory=0,& max_allocated_memory=0,max_usable_memory=10**8 LOGICAL,SAVE,PUBLIC::trace_allocations=.FALSE. INTERFACE RecordAllocation MODULE PROCEDURE RecordAllocation_i_sp_i_byte MODULE PROCEDURE RecordAllocation_i_sp_i_short MODULE PROCEDURE RecordAllocation_i_sp_i_sp MODULE PROCEDURE RecordAllocation_i_sp_i_dp MODULE PROCEDURE RecordAllocation_i_sp_r_sp MODULE PROCEDURE RecordAllocation_i_sp_r_dp MODULE PROCEDURE RecordAllocation_i_sp_l_short MODULE PROCEDURE RecordAllocation_i_sp_l_word MODULE PROCEDURE RecordAllocation_i_sp_c_ascii MODULE PROCEDURE RecordAllocation_i_dp_i_byte MODULE PROCEDURE RecordAllocation_i_dp_i_short MODULE PROCEDURE RecordAllocation_i_dp_i_sp MODULE PROCEDURE RecordAllocation_i_dp_i_dp MODULE PROCEDURE RecordAllocation_i_dp_r_sp MODULE PROCEDURE RecordAllocation_i_dp_r_dp MODULE PROCEDURE RecordAllocation_i_dp_l_short MODULE PROCEDURE RecordAllocation_i_dp_l_word MODULE PROCEDURE RecordAllocation_i_dp_c_ascii END INTERFACE CONTAINS SUBROUTINE CreateMonitors() IMPLICIT NONE CALL OPTION_STOPWATCH(io_unit_print=message_log_unit,io_unit_error=error_log_unit,& print_errors=.TRUE.,abort_errors=(non_critical_action=="S")) CALL CREATE_WATCH(timers) n_flops=0 n_reads=0 n_writes=0 allocated_memory=0 max_allocated_memory=0 END SUBROUTINE CreateMonitors SUBROUTINE DestroyMonitors() IMPLICIT NONE CALL DESTROY_WATCH(timers) END SUBROUTINE DestroyMonitors SUBROUTINE StartTimer(timer) IMPLICIT NONE INTEGER,INTENT(IN)::timer IF(timer<=0)THEN ELSE IF(timer>n_timers)THEN CALL NonCriticalError(message="Timer that is not available was requested",& caller="StartTimer") ELSE CALL START_WATCH(timers(timer),err=error_status) END IF END SUBROUTINE StartTimer SUBROUTINE StopTimer(timer) IMPLICIT NONE INTEGER,INTENT(IN)::timer IF(timer<0)THEN ELSE IF(timer>n_timers)THEN CALL NonCriticalError(message="Timer that is not available was requested",& caller="StopTimer") ELSE CALL STOP_WATCH(timers(timer),err=error_status) END IF END SUBROUTINE StopTimer SUBROUTINE ResetTimer(timer) IMPLICIT NONE INTEGER,INTENT(IN)::timer IF(timer<0)THEN ELSE IF(timer>n_timers)THEN CALL NonCriticalError(message="Timer that is not available was requested",& caller="ResetTimer") ELSE CALL RESET_WATCH(timers(timer),err=error_status) END IF END SUBROUTINE ResetTimer FUNCTION ReadTimer(timer)RESULT(elapsed_time) IMPLICIT NONE INTEGER,INTENT(IN)::timer REAL::elapsed_time IF(timer<0)THEN elapsed_time=0.0 ELSE IF(timer>n_timers)THEN CALL NonCriticalError(message="Timer that is not available was requested",& caller="ReadTimer") ELSE CALL READ_WATCH(READ_RESULT=elapsed_time,WATCH=timers(timer),& CLOCK="cpu",err=error_status) END IF END FUNCTION ReadTimer SUBROUTINE RecordAllocation_i_sp_i_byte(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_sp),INTENT(IN)::n_elements INTEGER(KIND=i_byte),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_sp_i_short(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_sp),INTENT(IN)::n_elements INTEGER(KIND=i_short),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_sp_i_sp(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_sp),INTENT(IN)::n_elements INTEGER(KIND=i_sp),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_sp_i_dp(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_sp),INTENT(IN)::n_elements INTEGER(KIND=i_dp),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_sp_r_sp(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_sp),INTENT(IN)::n_elements REAL(KIND=r_sp),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_sp_r_dp(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_sp),INTENT(IN)::n_elements REAL(KIND=r_dp),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_sp_l_short(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_sp),INTENT(IN)::n_elements LOGICAL(KIND=l_short),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_sp_l_word(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_sp),INTENT(IN)::n_elements LOGICAL(KIND=l_word),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_sp_c_ascii(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_sp),INTENT(IN)::n_elements CHARACTER(KIND=c_ascii),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_dp_i_byte(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_dp),INTENT(IN)::n_elements INTEGER(KIND=i_byte),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_dp_i_short(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_dp),INTENT(IN)::n_elements INTEGER(KIND=i_short),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_dp_i_sp(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_dp),INTENT(IN)::n_elements INTEGER(KIND=i_sp),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_dp_i_dp(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_dp),INTENT(IN)::n_elements INTEGER(KIND=i_dp),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_dp_r_sp(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_dp),INTENT(IN)::n_elements REAL(KIND=r_sp),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_dp_r_dp(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_dp),INTENT(IN)::n_elements REAL(KIND=r_dp),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_dp_l_short(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_dp),INTENT(IN)::n_elements LOGICAL(KIND=l_short),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_dp_l_word(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_dp),INTENT(IN)::n_elements LOGICAL(KIND=l_word),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE RecordAllocation_i_dp_c_ascii(n_elements,mold,caller,alloc_status) IMPLICIT NONE INTEGER(KIND=i_dp),INTENT(IN)::n_elements CHARACTER(KIND=c_ascii),INTENT(IN)::mold CHARACTER(LEN=*),INTENT(IN),OPTIONAL::caller INTEGER,INTENT(IN),OPTIONAL::alloc_status IF(trace_allocations)THEN IF(PRESENT(caller))THEN WRITE(message_print_unit,"(A20,A20,I10)")& caller," allocated (bytes):",n_elements*BIT_SIZE(mold)/8 ELSE WRITE(message_print_unit,"(A40,I10)")& "Someone (de)allocated (bytes):",n_elements*BIT_SIZE(mold)/8 END IF END IF allocated_memory=allocated_memory+n_elements*BIT_SIZE(mold)/8 max_allocated_memory=MAX(max_allocated_memory,allocated_memory) IF(allocated_memory>max_usable_memory)THEN CALL MemoryUsage() CALL NonCriticalError("Allocated memory has exceeded the usable capacity") END IF IF(PRESENT(alloc_status))THEN IF(alloc_status/=0)THEN CALL MemoryUsage() IF(PRESENT(caller))THEN CALL CriticalError(message="Memory could not be (de)allocated",caller=caller) ELSE CALL CriticalError(message="Memory could not be (de)allocated") END IF END IF END IF END SUBROUTINE SUBROUTINE MemoryUsage() IMPLICIT NONE WRITE(UNIT=message_print_unit,FMT=*)"At present allocated: ",allocated_memory,& " bytes, maximum allocated at one time: ",max_allocated_memory,& " bytes, still available: ",max_usable_memory-allocated_memory WRITE(UNIT=message_log_unit,FMT=*)"At present allocated: ",allocated_memory,& " bytes, maximum allocated at one time: ",max_allocated_memory END SUBROUTINE MemoryUsage END MODULE System_Monitors