13 USE stel_kinds,
only: rprec
48 REAL (rprec) :: vrnc = 0.0
66 INTEGER,
DIMENSION(2,data_max_indices) :: range_indices = 0
69 REAL (rprec),
DIMENSION(2) :: range_value = 0.0
77 REAL (rprec),
DIMENSION(:),
POINTER :: sem => null()
87 INTEGER,
DIMENSION(:),
POINTER :: ids => null()
89 INTEGER,
DIMENSION(:,:),
POINTER :: indices => null()
102 INTEGER,
DIMENSION(data_max_indices) :: indices = 0
112 REAL (rprec) :: sigma = 0.0
115 REAL (rprec),
DIMENSION(:),
POINTER :: correlation => null()
177 CHARACTER (len=*),
INTENT(in) :: param_name
178 INTEGER,
DIMENSION(2),
INTENT(in) :: indices
179 INTEGER,
INTENT(in) :: num_params
182 REAL (rprec) :: start_time
185 start_time = profiler_get_start_time()
197 CALL profiler_set_stop_time(
'param_construct_basic', start_time)
230 & vrnc, range_type, range_indices, &
231 & range_value, num_signals, &
240 CHARACTER (len=*),
INTENT(in) :: param_name
241 INTEGER,
DIMENSION(2),
INTENT(in) :: indices
242 REAL (rprec),
INTENT(in) :: vrnc
243 CHARACTER (len=*),
DIMENSION(2),
INTENT(in) :: range_type
244 INTEGER,
DIMENSION(2,2),
INTENT(in) :: range_indices
245 REAL (rprec),
DIMENSION(2),
INTENT(in) :: range_value
246 INTEGER,
INTENT(in) :: num_signals
247 INTEGER,
INTENT(in) :: num_params
250 REAL (rprec) :: value
251 REAL (rprec) :: start_time
254 start_time = profiler_get_start_time()
257 & indices, num_params)
261 CALL err_fatal(
'param_construct: ' // trim(param_name) //
262 &
' is an invalid reconstruction ' //
269 SELECT CASE (trim(range_type(1)))
291 SELECT CASE (trim(range_type(2)))
321 & //
' inital value is outside reconstruction parameter'
327 & //
' inital value is outside reconstruction parameter'
328 & //
' upper bound.')
330 CALL profiler_set_stop_time(
'param_construct_recon', start_time)
353 & set, set_indices, set_coeff, &
362 CHARACTER (len=*),
INTENT(in) :: param_name
363 INTEGER,
DIMENSION(2),
INTENT(in) :: indices
364 CHARACTER (len=*),
DIMENSION(:),
INTENT(in) :: set
365 INTEGER,
DIMENSION(:,:),
INTENT(in) :: set_indices
366 REAL (rprec),
DIMENSION(:),
INTENT(in) :: set_coeff
367 INTEGER,
INTENT(in) :: eq_comm
371 REAL (rprec) :: start_time
374 start_time = profiler_get_start_time()
377 & indices,
SIZE(set))
381 CALL err_fatal(
'param_construct: ' // trim(param_name) //
382 &
' is an invalid locking parameter')
405 CALL profiler_set_stop_time(
'param_construct_locking', start_time)
424 TYPE (param_class),
POINTER :: this
430 IF (
ASSOCIATED(this%recon))
THEN
432 IF (
ASSOCIATED(this%recon%sem))
THEN
433 DEALLOCATE(this%recon%sem)
434 this%recon%sem => null()
437 DEALLOCATE(this%recon)
441 IF (
ASSOCIATED(this%locks))
THEN
443 IF (
ASSOCIATED(this%locks%ids))
THEN
444 DEALLOCATE(this%locks%ids)
445 this%locks%ids => null()
448 IF (
ASSOCIATED(this%locks%indices))
THEN
449 DEALLOCATE(this%locks%indices)
450 this%locks%indices => null()
453 DEALLOCATE(this%locks)
457 IF (
ASSOCIATED(this%correlation))
THEN
458 DEALLOCATE(this%correlation)
459 this%correlation => null()
497 TYPE (param_class),
INTENT(in) :: this
498 TYPE (model_class),
INTENT(inout) :: a_model
499 REAL (rprec),
INTENT(in) :: value
500 INTEGER,
INTENT(in) :: eq_comm
501 LOGICAL,
INTENT(in) :: is_central
504 REAL (rprec) :: set_value
505 REAL (rprec) :: off_set_value
506 REAL (rprec) :: upper_value
507 REAL (rprec) :: lower_value
508 REAL (rprec) :: start_time
511 start_time = profiler_get_start_time()
516 off_set_value = this%recon%vrnc/2.0
526 IF (set_value - off_set_value .lt. lower_value)
THEN
530 set_value = lower_value + off_set_value
533 IF (is_central .and. (this%recon%range_type(2) .ne.
538 IF (set_value + off_set_value .gt. upper_value)
THEN
540 set_value = (upper_value + lower_value)/2.0
545 & this%indices(1), this%indices(2),
546 & set_value, eq_comm)
548 CALL profiler_set_stop_time(
'profiler_get_start_time',
559 IF (set_value + off_set_value .gt. upper_value)
THEN
565 set_value = upper_value - off_set_value
568 & this%indices(1), this%indices(2),
569 & set_value, eq_comm)
571 CALL profiler_set_stop_time(
'profiler_get_start_time',
579 & this%indices(1), this%indices(2),
580 & set_value, eq_comm)
582 CALL profiler_set_stop_time(
'profiler_get_start_time', start_time)
601 TYPE (param_class),
INTENT(in) :: this
602 TYPE (model_class),
INTENT(inout) :: a_model
603 INTEGER,
INTENT(in) :: eq_comm
608 REAL (rprec) :: inital_value
609 REAL (rprec) :: start_time
612 start_time = profiler_get_start_time()
619 DO i = 0,
SIZE(this%locks%ids)
620 temp = temp + this%correlation(i)
623 & this%locks%indices(i,1),
624 & this%locks%indices(i,2))
628 IF (inital_value .ne. temp)
THEN
630 & this%indices(1), this%indices(2),
634 CALL profiler_set_stop_time(
'param_set_lock_value', start_time)
661 REAL (rprec) :: start_time
664 start_time = profiler_get_start_time()
671 CALL profiler_set_stop_time(
'param_get_value', start_time)
695 REAL (rprec) :: start_time
698 start_time = profiler_get_start_time()
702 CALL profiler_set_stop_time(
'param_get_name', start_time)
726 REAL (rprec) :: start_time
729 start_time = profiler_get_start_time()
731 SELECT CASE (this%recon%range_type(1))
739 & this%recon%range_indices(1,1),
740 & this%recon%range_indices(1,2))
744 CALL profiler_set_stop_time(
'param_get_lower_range_value',
769 REAL (rprec) :: start_time
772 start_time = profiler_get_start_time()
774 SELECT CASE (this%recon%range_type(2))
782 & this%recon%range_indices(2,1),
783 & this%recon%range_indices(2,2))
787 CALL profiler_set_stop_time(
'param_get_upper_range_value',
811 REAL (rprec) :: start_time
814 start_time = profiler_get_start_time()
816 SELECT CASE (this%recon%range_type(1))
833 CALL profiler_set_stop_time(
'param_get_lower_range_type',
857 REAL (rprec) :: start_time
860 start_time = profiler_get_start_time()
862 SELECT CASE (this%recon%range_type(2))
879 CALL profiler_set_stop_time(
'param_get_upper_range_type',
906 REAL (rprec),
INTENT(in) :: value
909 REAL (rprec) :: start_time
912 start_time = profiler_get_start_time()
920 CALL profiler_set_stop_time(
'param_is_in_lower_range', start_time)
943 REAL (rprec),
INTENT(in) :: value
946 REAL (rprec) :: start_time
949 start_time = profiler_get_start_time()
957 CALL profiler_set_stop_time(
'param_is_in_upper_range', start_time)
986 USE v3_utilities,
only: err_fatal
991 TYPE (param_class),
INTENT(inout) :: this
992 TYPE (model_class),
INTENT(inout) :: a_model
993 INTEGER,
INTENT(in) :: eq_comm
994 LOGICAL,
INTENT(in) :: is_central
997 REAL (rprec) :: new_value
998 REAL (rprec) :: value
1001 REAL (rprec) :: start_time
1004 start_time = profiler_get_start_time()
1009 IF (is_central)
THEN
1010 step = abs(this%recon%vrnc)/2.0
1012 step = abs(this%recon%vrnc)
1018 IF (step .eq. 0.0)
THEN
1019 CALL err_fatal(
'param_increment: tried to take a ' //
1023 IF (is_central)
THEN
1026 &
value + step) .and.
1028 &
value - step))
THEN
1029 new_value =
value + step
1032 this%recon%delta = step
1040 new_value =
value + step
1043 this%recon%delta = step
1048 new_value =
value - step
1051 this%recon%delta = -step
1061 & this%indices(2), new_value, eq_comm)
1064 CALL err_fatal(
'param_increment: failed to change ' //
1065 &
'reconstruction. Try decreaing rp_vrnc ' //
1066 &
'or expanding the range.')
1069 CALL profiler_set_stop_time(
'param_increment', start_time)
1088 TYPE (param_class),
INTENT(inout) :: this
1089 TYPE (model_class),
INTENT(inout) :: a_model
1090 INTEGER,
INTENT(in) :: eq_comm
1093 REAL (rprec) :: value
1094 REAL (rprec) :: start_time
1097 start_time = profiler_get_start_time()
1100 value =
value - this%recon%delta
1103 & this%indices(2),
value, eq_comm)
1105 CALL profiler_set_stop_time(
'param_decrement', start_time)
1126 TYPE (param_class),
INTENT(in) :: this
1127 INTEGER,
INTENT(in) :: iou
1128 INTEGER,
INTENT(in) :: index
1129 TYPE (model_class),
INTENT(in) :: a_model
1132 REAL (rprec) :: start_time
1135 start_time = profiler_get_start_time()
1137 WRITE (iou,1000) index,
1139 & this%indices(1), this%indices(2),
1141 & this%sigma, this%recon%vrnc,
1146 & this%recon%range_indices(2,:),
1147 & this%recon%range_indices(1,:)
1148 1000
FORMAT(i3,2x,a18,2(1x,i4),3(2x,es12.5),2(2x,a13),2(2x,es12.5),
1151 CALL profiler_set_stop_time(
'param_write', start_time)
1171 TYPE (param_class),
INTENT(in) :: this
1172 INTEGER,
INTENT(in) :: iou
1173 INTEGER,
INTENT(in) :: index
1174 TYPE (model_class),
INTENT(in) :: a_model
1177 REAL (rprec) :: start_time
1180 start_time = profiler_get_start_time()
1182 WRITE (iou,1000) index,
1184 & this%indices(1), this%indices(2),
1186 1000
FORMAT(i3,2x,a18,2(1x,i4),2(2x,es12.5))
1188 CALL profiler_set_stop_time(
'param_write_short', start_time)
1207 INTEGER,
INTENT(in) :: iou
1210 REAL (rprec) :: start_time
1213 start_time = profiler_get_start_time()
1216 WRITE (iou,*)
' *** Reconstruction parameters'
1219 CALL profiler_set_stop_time(
'param_write_header', start_time)
1221 1000
FORMAT (
'irp',2x,
'p_type',13x,
'inx1',1x,
'inx2',2x,
'value',9x,
1222 &
'sigma',9x,
'vrnc',10x,
'range_type_h',3x,
'range_type_l',3x,
1223 &
'r_value_h',5x,
'r_value_l',5x,
1224 &
'r_inx1_h',1x,
'r_inx2_h',2x,
'r_inx1_l',1x,
'r_inx2_l')
1243 INTEGER,
INTENT(in) :: iou
1246 REAL (rprec) :: start_time
1249 start_time = profiler_get_start_time()
1252 WRITE (iou,*)
' *** Derived parameters'
1255 CALL profiler_set_stop_time(
'param_write_header_short',
1258 1000
FORMAT (
'irp',2x,
'p_type',13x,
'inx1',1x,
'inx2',2x,
'value',9x,
1279 TYPE (param_class),
INTENT(in) :: this
1280 INTEGER,
INTENT(in) :: iou
1281 TYPE (model_class),
INTENT(in) :: a_model
1284 CHARACTER (len=20) :: row_format
1285 REAL (rprec) :: start_time
1288 start_time = profiler_get_start_time()
1290 WRITE (row_format,1000)
SIZE(this%correlation)
1294 CALL profiler_set_stop_time(
'param_write_correlation', start_time)
1296 1000
FORMAT (
'(a12,',i3,
'(2x,es12.5))')
1327 & current_step, index, &
1328 & param_value_id, param_sigma_id, &
1329 & param_corr_id, param_sem_id)
1335 TYPE (param_class),
INTENT(in) :: this
1336 TYPE (model_class),
INTENT(in) :: a_model
1337 INTEGER,
INTENT(in) :: result_ncid
1338 INTEGER,
INTENT(in) :: current_step
1339 INTEGER,
INTENT(in) :: index
1340 INTEGER,
INTENT(in) :: param_value_id
1341 INTEGER,
INTENT(in) :: param_sigma_id
1342 INTEGER,
INTENT(in) :: param_corr_id
1343 INTEGER,
INTENT(in) :: param_sem_id
1347 REAL (rprec) :: start_time
1350 start_time = profiler_get_start_time()
1353 & current_step, index,
1354 & param_value_id, param_sigma_id,
1357 status = nf_put_vara_double(result_ncid, param_sem_id,
1358 & (/ 1, index, current_step /),
1359 & (/
SIZE(this%recon%sem), 1, 1 /),
1362 CALL profiler_set_stop_time(
'param_write_step_data_1', start_time)
1387 & current_step, index, &
1388 & param_value_id, param_sigma_id, &
1395 TYPE (param_class),
INTENT(in) :: this
1396 TYPE (model_class),
INTENT(in) :: a_model
1397 INTEGER,
INTENT(in) :: result_ncid
1398 INTEGER,
INTENT(in) :: current_step
1399 INTEGER,
INTENT(in) :: index
1400 INTEGER,
INTENT(in) :: param_value_id
1401 INTEGER,
INTENT(in) :: param_sigma_id
1402 INTEGER,
INTENT(in) :: param_corr_id
1406 REAL (rprec) :: start_time
1409 start_time = profiler_get_start_time()
1411 status = nf_put_var1_double(result_ncid, param_value_id,
1412 & (/ index, current_step /),
1414 CALL assert_eq(status, nf_noerr, nf_strerror(status))
1416 status = nf_put_var1_double(result_ncid, param_sigma_id,
1417 & (/ index, current_step /),
1419 CALL assert_eq(status, nf_noerr, nf_strerror(status))
1421 status = nf_put_vara_double(result_ncid, param_corr_id,
1422 & (/ 1, index, current_step /),
1423 & (/
SIZE(this%correlation), 1, 1 /),
1425 CALL assert_eq(status, nf_noerr, nf_strerror(status))
1427 CALL profiler_set_stop_time(
'param_write_step_data_2', start_time)
1453 SUBROUTINE param_restart(this, a_model, result_ncid, current_step, &
1454 & index, param_value_id, param_sigma_id, &
1455 & param_corr_id, eq_comm, is_central)
1461 TYPE (param_class),
INTENT(inout) :: this
1462 TYPE (model_class),
INTENT(inout) :: a_model
1463 INTEGER,
INTENT(in) :: result_ncid
1464 INTEGER,
INTENT(in) :: current_step
1465 INTEGER,
INTENT(in) :: index
1466 INTEGER,
INTENT(in) :: param_value_id
1467 INTEGER,
INTENT(in) :: param_sigma_id
1468 INTEGER,
INTENT(in) :: param_corr_id
1469 INTEGER,
INTENT(in) :: eq_comm
1470 LOGICAL,
INTENT(in) :: is_central
1474 REAL (rprec) :: temp_value
1475 REAL (rprec) :: start_time
1478 start_time = profiler_get_start_time()
1480 status = nf_get_var1_double(result_ncid, param_value_id,
1481 & (/ index, current_step /), temp_value)
1482 CALL assert_eq(status, nf_noerr, nf_strerror(status))
1486 status = nf_put_var1_double(result_ncid, param_sigma_id,
1487 & (/ index, current_step /),
1489 CALL assert_eq(status, nf_noerr, nf_strerror(status))
1491 status = nf_put_vara_double(result_ncid, param_corr_id,
1492 & (/ 1, index, current_step /),
1493 & (/
SIZE(this%correlation), 1, 1 /),
1495 CALL assert_eq(status, nf_noerr, nf_strerror(status))
1497 CALL profiler_set_stop_time(
'param_restart', start_time)
1523 TYPE (param_class),
INTENT(inout) :: this
1524 TYPE (model_class),
INTENT(inout) :: a_model
1525 INTEGER,
INTENT(in) :: recon_comm
1526 INTEGER,
INTENT(in) :: eq_comm
1527 LOGICAL,
INTENT(in) :: is_central
1529 #if defined(MPI_OPT)
1532 REAL (rprec) :: value
1534 REAL (rprec) :: start_time
1537 start_time = profiler_get_start_time()
1539 CALL mpi_comm_rank(recon_comm, mpi_rank, error)
1541 IF (mpi_rank .eq. 0)
THEN
1545 CALL mpi_bcast(
value, 1, mpi_real8, 0, recon_comm, error)
1547 IF (mpi_rank .gt. 0)
THEN
1551 CALL profiler_set_stop_time(
'param_sync_value', start_time)
1572 TYPE (param_class),
INTENT(inout) :: this
1573 INTEGER,
INTENT(in) :: index
1574 INTEGER,
INTENT(in) :: recon_comm
1576 #if defined(MPI_OPT)
1580 INTEGER :: mpi_request
1581 REAL (rprec) :: start_time
1584 start_time = profiler_get_start_time()
1586 CALL mpi_comm_size(recon_comm, mpi_size, error)
1591 CALL mpi_isend(this%recon%delta, 1, mpi_real8, 0, index,
1592 & recon_comm, mpi_request, error)
1594 CALL profiler_set_stop_time(
'param_send_delta', start_time)
1614 TYPE (param_class),
INTENT(inout) :: this
1615 INTEGER,
INTENT(in) :: index
1616 INTEGER,
INTENT(in) :: recon_comm
1618 #if defined(MPI_OPT)
1621 REAL (rprec) :: start_time
1624 start_time = profiler_get_start_time()
1626 CALL mpi_recv(this%recon%delta, 1, mpi_real8, mpi_any_source,
1627 & index, recon_comm, mpi_status_ignore, error)
1629 CALL profiler_set_stop_time(
'param_recv_delta', start_time)
1649 TYPE (param_class),
INTENT(inout) :: this
1650 INTEGER,
INTENT(in) :: recon_comm
1652 #if defined(MPI_OPT)
1655 REAL (rprec) :: start_time
1658 start_time = profiler_get_start_time()
1660 CALL mpi_bcast(this%recon%delta, 1, mpi_real8, 0, recon_comm,
1663 CALL profiler_set_stop_time(
'param_sync_delta', start_time)
1684 & eq_comm, is_central)
1689 TYPE (param_class),
INTENT(inout) :: this
1690 TYPE (model_class),
INTENT(inout) :: a_model
1691 INTEGER,
INTENT(in) :: index
1692 INTEGER,
INTENT(in) :: recon_comm
1693 INTEGER,
INTENT(in) :: eq_comm
1694 LOGICAL,
INTENT(in) :: is_central
1696 #if defined(MPI_OPT)
1699 REAL (rprec) :: value
1701 REAL (rprec) :: start_time
1704 start_time = profiler_get_start_time()
1706 CALL mpi_comm_rank(recon_comm, mpi_rank, error)
1708 IF (mpi_rank .eq. index)
THEN
1710 CALL mpi_ssend(
value, 1, mpi_real8, 0, mpi_rank, recon_comm,
1712 ELSE IF (mpi_rank .eq. 0)
THEN
1713 CALL mpi_recv(
value, 1, mpi_real8, index, index, recon_comm,
1714 & mpi_status_ignore, error)
1718 CALL profiler_set_stop_time(
'param_sync_child', start_time)