60 logical,
private,
allocatable :: inuse(:)
62 integer,
private :: n_entries = 0
64 integer,
private :: n_inuse = 0
66 integer,
private :: expansion_size = 10
70 procedure,
private, pass(this) ::
expand
152 integer,
optional,
intent(in) :: size
153 integer,
optional,
intent(in) :: expansion_size
154 type(
dofmap_t),
target,
intent(in),
optional :: dof
160 if (
present(size)) s =
size
161 if (
present(dof)) this%dof => dof
163 allocate(this%entries(s))
164 allocate(this%inuse(s))
165 this%inuse(:) = .false.
167 this%expansion_size = 10
168 if (
present(expansion_size)) this%expansion_size = expansion_size
177 if (
allocated(this%inuse))
then
178 if(any(this%inuse))
then
179 call neko_error(
"scratch_registry::free: " // &
180 "Cannot free scratch registry with in-use entries.")
182 deallocate(this%inuse)
185 if (
allocated(this%entries))
then
186 do i = 1, this%n_entries
187 call this%entries(i)%free()
190 deallocate(this%entries)
193 if (
associated(this%dof))
nullify(this%dof)
198 this%expansion_size = 10
208 type(
dofmap_t),
target,
intent(in) :: dof
210 if (
associated(this%dof, dof))
then
212 else if (
associated(this%dof))
then
213 call neko_error(
"scratch_registry::set_dofmap: "&
214 //
"Dofmap is already assigned to scratch registry.")
233 n = count(this%inuse)
241 if (
allocated(this%entries))
then
242 n =
size(this%entries)
253 n = this%expansion_size
259 integer,
intent(in) :: index
267 logical,
allocatable :: temp2(:)
273 call move_alloc(this%entries, temp)
274 call move_alloc(this%inuse, temp2)
277 allocate(this%entries(n + this%expansion_size))
278 allocate(this%inuse(n + this%expansion_size), source = .false.)
282 call this%entries(i)%move_from(temp(i))
283 this%inuse(i) = temp2(i)
288 if (
allocated(temp))
deallocate(temp)
289 if (
allocated(temp2))
deallocate(temp2)
302 integer,
intent(inout) :: index
303 integer,
intent(in) :: n
304 logical,
intent(in) :: clear
306 associate(entries => this%entries, n_entries => this%n_entries, &
307 n_inuse => this%n_inuse)
309 do index = 1, this%get_size()
310 if (.not. this%inuse(index))
then
312 if (.not. entries(index)%is_allocated())
then
313 call entries(index)%init_host_array(n)
314 n_entries = n_entries + 1
315 else if (trim(entries(index)%get_type()) .ne.
'host_array')
then
319 v => entries(index)%get_host_array()
320 if (v%size() .ne. n)
then
325 if (clear)
call rzero(v%x, v%size())
326 this%inuse(index) = .true.
327 this%n_inuse = this%n_inuse + 1
333 index = n_entries + 1
335 n_entries = n_entries + 1
336 n_inuse = n_inuse + 1
337 this%inuse(n_entries) = .true.
338 call this%entries(n_entries)%init_host_array(n)
339 v => this%entries(n_entries)%get_host_array()
352 type(device_array_t),
pointer,
intent(inout) :: v
353 integer,
intent(inout) :: index
354 integer,
intent(in) :: n
355 logical,
intent(in) :: clear
357 associate(entries => this%entries, n_entries => this%n_entries, &
358 n_inuse => this%n_inuse)
360 do index = 1, this%get_size()
361 if (.not. this%inuse(index))
then
363 if (.not. entries(index)%is_allocated())
then
364 call entries(index)%init_device_array(n)
365 n_entries = n_entries + 1
366 else if (trim(entries(index)%get_type()) .ne.
'device_array')
then
370 v => entries(index)%get_device_array()
371 if (v%size() .ne. n)
then
376 if (clear)
call device_rzero(v%x_d, v%size())
377 this%inuse(index) = .true.
378 this%n_inuse = this%n_inuse + 1
384 index = n_entries + 1
386 n_entries = n_entries + 1
387 n_inuse = n_inuse + 1
388 this%inuse(n_entries) = .true.
389 call this%entries(n_entries)%init_device_array(n)
390 v => this%entries(n_entries)%get_device_array()
402 type(vector_t),
pointer,
intent(inout) :: v
403 integer,
intent(inout) :: index
404 integer,
intent(in) :: n
405 logical,
intent(in) :: clear
407 associate(entries => this%entries, n_entries => this%n_entries, &
408 n_inuse => this%n_inuse)
410 do index = 1, this%get_size()
411 if (.not. this%inuse(index))
then
413 if (.not. entries(index)%is_allocated())
then
414 call entries(index)%init_vector(n)
415 n_entries = n_entries + 1
416 else if (trim(entries(index)%get_type()) .ne.
'vector')
then
420 v => entries(index)%get_vector()
421 if (v%size() .ne. n)
then
426 if (clear)
call vector_rzero(v)
427 this%inuse(index) = .true.
428 this%n_inuse = this%n_inuse + 1
434 index = n_entries + 1
436 n_entries = n_entries + 1
437 n_inuse = n_inuse + 1
438 this%inuse(n_entries) = .true.
439 call this%entries(n_entries)%init_vector(n)
440 v => this%entries(n_entries)%get_vector()
453 type(matrix_t),
pointer,
intent(inout) :: m
454 integer,
intent(inout) :: index
455 integer,
intent(in) :: nrows, ncols
456 logical,
intent(in) :: clear
458 associate(entries => this%entries, n_entries => this%n_entries, &
459 n_inuse => this%n_inuse)
461 do index = 1, this%get_size()
462 if (.not. this%inuse(index))
then
464 if (.not. entries(index)%is_allocated())
then
465 call entries(index)%init_matrix(nrows, ncols)
466 n_entries = n_entries + 1
467 else if (trim(entries(index)%get_type()) .ne.
'matrix')
then
471 m => entries(index)%get_matrix()
472 if (m%get_nrows() .ne. nrows .or. &
473 m%get_ncols() .ne. ncols)
then
478 if (clear)
call matrix_rzero(m)
479 this%inuse(index) = .true.
480 this%n_inuse = this%n_inuse + 1
486 index = n_entries + 1
488 n_entries = n_entries + 1
489 n_inuse = n_inuse + 1
490 this%inuse(n_entries) = .true.
491 call this%entries(n_entries)%init_matrix(nrows, ncols)
492 m => this%entries(n_entries)%get_matrix()
504 type(field_t),
pointer,
intent(inout) :: f
505 integer,
intent(inout) :: index
506 logical,
intent(in) :: clear
507 character(len=10) :: name
509 if (.not.
associated(this%dof))
then
510 call neko_error(
"scratch_registry::request_field: "&
511 //
"No dofmap assigned to scratch registry.")
514 associate(entries => this%entries, n_entries => this%n_entries, &
515 n_inuse => this%n_inuse)
517 do index = 1, this%get_size()
518 if (.not. this%inuse(index))
then
520 if (.not. entries(index)%is_allocated())
then
521 write(name,
"(A3,I0.3)")
"wrk", index
522 call entries(index)%init_field(this%dof, trim(name))
523 n_entries = n_entries + 1
524 else if (entries(index)%get_type() .ne.
'field')
then
528 f => entries(index)%get_field()
529 if (clear)
call field_rzero(f)
530 this%inuse(index) = .true.
531 this%n_inuse = this%n_inuse + 1
537 index = n_entries + 1
539 n_entries = n_entries + 1
540 n_inuse = n_inuse + 1
541 this%inuse(n_entries) = .true.
542 write (name,
"(A3,I0.3)")
"wrk", index
543 call this%entries(n_entries)%init_field(this%dof, trim(name))
544 f => this%entries(n_entries)%get_field()
553 integer,
intent(inout) :: index
555 if (trim(this%entries(index)%get_type()) .ne.
'host_array')
then
556 call neko_error(
"scratch_registry::relinquish_host_array_single: " &
557 //
"Register entry is not a host_array.")
560 this%inuse(index) = .false.
561 this%n_inuse = this%n_inuse - 1
568 integer,
intent(inout) :: indices(:)
571 do i = 1,
size(indices)
572 if (trim(this%entries(indices(i))%get_type()) .ne.
'host_array')
then
573 call neko_error(
"scratch_registry::relinquish_host_array_single: " &
574 //
"Register entry is not a host_array.")
577 this%inuse(indices(i)) = .false.
579 this%n_inuse = this%n_inuse -
size(indices)
586 integer,
intent(inout) :: index
588 if (trim(this%entries(index)%get_type()) .ne.
'device_array')
then
589 call neko_error(
"scratch_registry::relinquish_device_array_single: " &
590 //
"Register entry is not a device_array.")
593 this%inuse(index) = .false.
594 this%n_inuse = this%n_inuse - 1
601 integer,
intent(inout) :: indices(:)
604 do i = 1,
size(indices)
605 if (trim(this%entries(indices(i))%get_type()) .ne.
'device_array')
then
606 call neko_error(
"scratch_registry::relinquish_device_array_single: " &
607 //
"Register entry is not a device_array.")
610 this%inuse(indices(i)) = .false.
612 this%n_inuse = this%n_inuse -
size(indices)
619 integer,
intent(inout) :: index
621 if (trim(this%entries(index)%get_type()) .ne.
'vector')
then
622 call neko_error(
"scratch_registry::relinquish_vector_single: " &
623 //
"Register entry is not a vector.")
626 this%inuse(index) = .false.
627 this%n_inuse = this%n_inuse - 1
634 integer,
intent(inout) :: indices(:)
637 do i = 1,
size(indices)
638 if (trim(this%entries(indices(i))%get_type()) .ne.
'vector')
then
639 call neko_error(
"scratch_registry::relinquish_vector_single: " &
640 //
"Register entry is not a vector.")
643 this%inuse(indices(i)) = .false.
645 this%n_inuse = this%n_inuse -
size(indices)
652 integer,
intent(inout) :: index
654 if (trim(this%entries(index)%get_type()) .ne.
'matrix')
then
655 call neko_error(
"scratch_registry::relinquish_matrix_single: " &
656 //
"Register entry is not a matrix.")
659 this%inuse(index) = .false.
660 this%n_inuse = this%n_inuse - 1
667 integer,
intent(inout) :: indices(:)
670 do i = 1,
size(indices)
671 if (trim(this%entries(indices(i))%get_type()) .ne.
'matrix')
then
672 call neko_error(
"scratch_registry::relinquish_matrix_single: " &
673 //
"Register entry is not a matrix.")
676 this%inuse(indices(i)) = .false.
678 this%n_inuse = this%n_inuse -
size(indices)
685 integer,
intent(inout) :: index
687 if (trim(this%entries(index)%get_type()) .ne.
'field')
then
688 call neko_error(
"scratch_registry::relinquish_field_single: " &
689 //
"Register entry is not a field.")
692 this%inuse(index) = .false.
693 this%n_inuse = this%n_inuse - 1
700 integer,
intent(inout) :: indices(:)
703 do i = 1,
size(indices)
704 if (trim(this%entries(indices(i))%get_type()) .ne.
'field')
then
705 call neko_error(
"scratch_registry::relinquish_field_single: " &
706 //
"Register entry is not a field.")
709 this%inuse(indices(i)) = .false.
711 this%n_inuse = this%n_inuse -
size(indices)
718 integer,
intent(inout) :: index
720 this%inuse(index) = .false.
721 this%n_inuse = this%n_inuse - 1
728 integer,
intent(inout) :: indices(:)
731 do i = 1,
size(indices)
732 this%inuse(indices(i)) = .false.
734 this%n_inuse = this%n_inuse -
size(indices)
Module containing device only array type.
subroutine, public device_rzero(a_d, n, strm)
Zero a real vector.
Defines a mapping of the degrees of freedom.
subroutine, public field_rzero(a, n)
Zero a real vector.
Module containing host-only array type.
subroutine, public rzero(a, n)
Zero a real vector.
subroutine, public matrix_rzero(a, n)
Zero a real matrix .
Defines a registry entry for storing and requesting temporary objects This is used in the registries ...
Defines a registry for storing and requesting temporary objects This can be used when you have a func...
subroutine relinquish_matrix_single(this, index)
Relinquish the use of a matrix in the registry.
pure logical function get_inuse(this, index)
Get the inuse status for a given index.
pure integer function get_n_inuse(this)
Get the number of objects currently in use.
subroutine scratch_registry_free(this)
Destructor.
subroutine request_field(this, f, index, clear)
Get a field from the registry by assigning it to a pointer.
subroutine relinquish_matrix_multiple(this, indices)
Relinquish the use of multiple matrices in the registry.
subroutine relinquish_host_array_single(this, index)
Relinquish the use of a host_array in the registry.
pure integer function get_n_entries(this)
Get the number of objects stored in the registry.
subroutine relinquish_device_array_multiple(this, indices)
Relinquish the use of multiple device_arrays in the registry.
subroutine request_host_array(this, v, index, n, clear)
Get a host_array from the registry by assigning it to a pointer.
subroutine relinquish_field_single(this, index)
Relinquish the use of a field in the registry.
subroutine relinquish_host_array_multiple(this, indices)
Relinquish the use of multiple host_arrays in the registry.
pure integer function get_size(this)
Get the size of the objects array.
subroutine scratch_registry_set_dofmap(this, dof)
Assign a dofmap to the scratch registry.
subroutine relinquish_field_multiple(this, indices)
Relinquish the use of multiple fields in the registry.
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
subroutine relinquish_vector_multiple(this, indices)
Relinquish the use of multiple vectors in the registry.
subroutine relinquish_device_array_single(this, index)
Relinquish the use of a device_array in the registry.
subroutine relinquish_vector_single(this, index)
Relinquish the use of a vector in the registry.
subroutine request_matrix(this, m, index, nrows, ncols, clear)
Get a matrix from the registry by assigning it to a pointer.
subroutine request_vector(this, v, index, n, clear)
Get a vector from the registry by assigning it to a pointer.
subroutine request_device_array(this, v, index, n, clear)
Get a device_array from the registry by assigning it to a pointer.
subroutine scratch_registry_init(this, size, expansion_size, dof)
Constructor, optionally taking initial registry and expansion size as argument.
subroutine relinquish_multiple(this, indices)
Relinquish the use of multiple objects in the registry.
subroutine relinquish_single(this, index)
Relinquish the use of an object in the registry.
pure integer function get_expansion_size(this)
Get the expansion size.
subroutine, public vector_rzero(a, n)
Zero a real vector.
Device-only temporary array.
Host-only temporary array.