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)
301 integer,
intent(inout) :: index
302 integer,
intent(in) :: n
303 logical,
intent(in) :: clear
305 associate(entries => this%entries, n_entries => this%n_entries, &
306 n_inuse => this%n_inuse)
308 do index = 1, this%get_size()
309 if (.not. this%inuse(index))
then
311 if (.not. entries(index)%is_allocated())
then
312 call entries(index)%init_host_array(n)
313 n_entries = n_entries + 1
314 else if (trim(entries(index)%get_type()) .ne.
'host_array')
then
318 v => entries(index)%get_host_array()
319 if (v%size() .ne. n)
then
324 if (clear)
call rzero(v%x, v%size())
325 this%inuse(index) = .true.
326 this%n_inuse = this%n_inuse + 1
332 index = n_entries + 1
334 n_entries = n_entries + 1
335 n_inuse = n_inuse + 1
336 this%inuse(n_entries) = .true.
337 call this%entries(n_entries)%init_host_array(n)
338 v => this%entries(n_entries)%get_host_array()
350 type(device_array_t),
pointer,
intent(inout) :: v
351 integer,
intent(inout) :: index
352 integer,
intent(in) :: n
353 logical,
intent(in) :: clear
355 associate(entries => this%entries, n_entries => this%n_entries, &
356 n_inuse => this%n_inuse)
358 do index = 1, this%get_size()
359 if (.not. this%inuse(index))
then
361 if (.not. entries(index)%is_allocated())
then
362 call entries(index)%init_device_array(n)
363 n_entries = n_entries + 1
364 else if (trim(entries(index)%get_type()) .ne.
'device_array')
then
368 v => entries(index)%get_device_array()
369 if (v%size() .ne. n)
then
374 if (clear)
call device_rzero(v%x_d, v%size())
375 this%inuse(index) = .true.
376 this%n_inuse = this%n_inuse + 1
382 index = n_entries + 1
384 n_entries = n_entries + 1
385 n_inuse = n_inuse + 1
386 this%inuse(n_entries) = .true.
387 call this%entries(n_entries)%init_device_array(n)
388 v => this%entries(n_entries)%get_device_array()
400 type(vector_t),
pointer,
intent(inout) :: v
401 integer,
intent(inout) :: index
402 integer,
intent(in) :: n
403 logical,
intent(in) :: clear
405 associate(entries => this%entries, n_entries => this%n_entries, &
406 n_inuse => this%n_inuse)
408 do index = 1, this%get_size()
409 if (.not. this%inuse(index))
then
411 if (.not. entries(index)%is_allocated())
then
412 call entries(index)%init_vector(n)
413 n_entries = n_entries + 1
414 else if (trim(entries(index)%get_type()) .ne.
'vector')
then
418 v => entries(index)%get_vector()
419 if (v%size() .ne. n)
then
424 if (clear)
call vector_rzero(v)
425 this%inuse(index) = .true.
426 this%n_inuse = this%n_inuse + 1
432 index = n_entries + 1
434 n_entries = n_entries + 1
435 n_inuse = n_inuse + 1
436 this%inuse(n_entries) = .true.
437 call this%entries(n_entries)%init_vector(n)
438 v => this%entries(n_entries)%get_vector()
451 type(matrix_t),
pointer,
intent(inout) :: m
452 integer,
intent(inout) :: index
453 integer,
intent(in) :: nrows, ncols
454 logical,
intent(in) :: clear
456 associate(entries => this%entries, n_entries => this%n_entries, &
457 n_inuse => this%n_inuse)
459 do index = 1, this%get_size()
460 if (.not. this%inuse(index))
then
462 if (.not. entries(index)%is_allocated())
then
463 call entries(index)%init_matrix(nrows, ncols)
464 n_entries = n_entries + 1
465 else if (trim(entries(index)%get_type()) .ne.
'matrix')
then
469 m => entries(index)%get_matrix()
470 if (m%get_nrows() .ne. nrows .or. &
471 m%get_ncols() .ne. ncols)
then
476 if (clear)
call matrix_rzero(m)
477 this%inuse(index) = .true.
478 this%n_inuse = this%n_inuse + 1
484 index = n_entries + 1
486 n_entries = n_entries + 1
487 n_inuse = n_inuse + 1
488 this%inuse(n_entries) = .true.
489 call this%entries(n_entries)%init_matrix(nrows, ncols)
490 m => this%entries(n_entries)%get_matrix()
502 type(field_t),
pointer,
intent(inout) :: f
503 integer,
intent(inout) :: index
504 logical,
intent(in) :: clear
505 character(len=10) :: name
507 if (.not.
associated(this%dof))
then
508 call neko_error(
"scratch_registry::request_field: "&
509 //
"No dofmap assigned to scratch registry.")
512 associate(entries => this%entries, n_entries => this%n_entries, &
513 n_inuse => this%n_inuse)
515 do index = 1, this%get_size()
516 if (.not. this%inuse(index))
then
518 if (.not. entries(index)%is_allocated())
then
519 write(name,
"(A3,I0.3)")
"wrk", index
520 call entries(index)%init_field(this%dof, trim(name))
521 n_entries = n_entries + 1
522 else if (entries(index)%get_type() .ne.
'field')
then
526 f => entries(index)%get_field()
527 if (clear)
call field_rzero(f)
528 this%inuse(index) = .true.
529 this%n_inuse = this%n_inuse + 1
535 index = n_entries + 1
537 n_entries = n_entries + 1
538 n_inuse = n_inuse + 1
539 this%inuse(n_entries) = .true.
540 write (name,
"(A3,I0.3)")
"wrk", index
541 call this%entries(n_entries)%init_field(this%dof, trim(name))
542 f => this%entries(n_entries)%get_field()
551 integer,
intent(inout) :: index
553 if (trim(this%entries(index)%get_type()) .ne.
'host_array')
then
554 call neko_error(
"scratch_registry::relinquish_host_array_single: " &
555 //
"Register entry is not a host_array.")
558 this%inuse(index) = .false.
559 this%n_inuse = this%n_inuse - 1
566 integer,
intent(inout) :: indices(:)
569 do i = 1,
size(indices)
570 if (trim(this%entries(indices(i))%get_type()) .ne.
'host_array')
then
571 call neko_error(
"scratch_registry::relinquish_host_array_single: " &
572 //
"Register entry is not a host_array.")
575 this%inuse(indices(i)) = .false.
577 this%n_inuse = this%n_inuse -
size(indices)
584 integer,
intent(inout) :: index
586 if (trim(this%entries(index)%get_type()) .ne.
'device_array')
then
587 call neko_error(
"scratch_registry::relinquish_device_array_single: " &
588 //
"Register entry is not a device_array.")
591 this%inuse(index) = .false.
592 this%n_inuse = this%n_inuse - 1
599 integer,
intent(inout) :: indices(:)
602 do i = 1,
size(indices)
603 if (trim(this%entries(indices(i))%get_type()) .ne.
'device_array')
then
604 call neko_error(
"scratch_registry::relinquish_device_array_single: " &
605 //
"Register entry is not a device_array.")
608 this%inuse(indices(i)) = .false.
610 this%n_inuse = this%n_inuse -
size(indices)
617 integer,
intent(inout) :: index
619 if (trim(this%entries(index)%get_type()) .ne.
'vector')
then
620 call neko_error(
"scratch_registry::relinquish_vector_single: " &
621 //
"Register entry is not a vector.")
624 this%inuse(index) = .false.
625 this%n_inuse = this%n_inuse - 1
632 integer,
intent(inout) :: indices(:)
635 do i = 1,
size(indices)
636 if (trim(this%entries(indices(i))%get_type()) .ne.
'vector')
then
637 call neko_error(
"scratch_registry::relinquish_vector_single: " &
638 //
"Register entry is not a vector.")
641 this%inuse(indices(i)) = .false.
643 this%n_inuse = this%n_inuse -
size(indices)
650 integer,
intent(inout) :: index
652 if (trim(this%entries(index)%get_type()) .ne.
'matrix')
then
653 call neko_error(
"scratch_registry::relinquish_matrix_single: " &
654 //
"Register entry is not a matrix.")
657 this%inuse(index) = .false.
658 this%n_inuse = this%n_inuse - 1
665 integer,
intent(inout) :: indices(:)
668 do i = 1,
size(indices)
669 if (trim(this%entries(indices(i))%get_type()) .ne.
'matrix')
then
670 call neko_error(
"scratch_registry::relinquish_matrix_single: " &
671 //
"Register entry is not a matrix.")
674 this%inuse(indices(i)) = .false.
676 this%n_inuse = this%n_inuse -
size(indices)
683 integer,
intent(inout) :: index
685 if (trim(this%entries(index)%get_type()) .ne.
'field')
then
686 call neko_error(
"scratch_registry::relinquish_field_single: " &
687 //
"Register entry is not a field.")
690 this%inuse(index) = .false.
691 this%n_inuse = this%n_inuse - 1
698 integer,
intent(inout) :: indices(:)
701 do i = 1,
size(indices)
702 if (trim(this%entries(indices(i))%get_type()) .ne.
'field')
then
703 call neko_error(
"scratch_registry::relinquish_field_single: " &
704 //
"Register entry is not a field.")
707 this%inuse(indices(i)) = .false.
709 this%n_inuse = this%n_inuse -
size(indices)
716 integer,
intent(inout) :: index
718 this%inuse(index) = .false.
719 this%n_inuse = this%n_inuse - 1
726 integer,
intent(inout) :: indices(:)
729 do i = 1,
size(indices)
730 this%inuse(indices(i)) = .false.
732 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.