Neko 1.99.3
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
host_array.f90
Go to the documentation of this file.
1! Copyright (c) 2026, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
35 use num_types, only : rp
36 use math, only : rzero, copy
37
38 implicit none
39 private
40
42 type, public :: host_array_t
44 real(kind=rp), allocatable :: x(:)
46 integer, private :: n = 0
47 contains
49 procedure, pass(this) :: init => host_array_init
51 procedure, pass(this) :: free => host_array_free
53 procedure, private, pass(this) :: allocate => host_array_allocate
55 procedure, pass(this) :: size => host_array_size
57 procedure, pass(this) :: is_allocated => host_array_is_allocated
59 procedure, pass(this) :: assign => host_array_assign
60
62 generic :: assignment(=) => assign
63
64
65 end type host_array_t
66
67contains
68
72 subroutine host_array_init(this, size)
73 class(host_array_t), intent(inout) :: this
74 integer, intent(in) :: size
75
76 call this%free()
77 call this%allocate(size)
78 call rzero(this%x, this%n)
79
80 end subroutine host_array_init
81
84 subroutine host_array_free(this)
85 class(host_array_t), intent(inout) :: this
86
87 this%n = 0
88 if (allocated(this%x)) deallocate(this%x)
89
90 end subroutine host_array_free
91
95 subroutine host_array_allocate(this, size)
96 class(host_array_t), intent(inout) :: this
97 integer, intent(in) :: size
98
99 this%n = size
100 allocate(this%x(size))
101
102 end subroutine host_array_allocate
103
107 subroutine host_array_assign(this, source)
108 class(host_array_t), intent(inout) :: this
109 class(host_array_t), intent(in) :: source
110
111 if (.not. source%is_allocated()) then
112 call this%free()
113 return
114 else if (source%size() .ne. this%size()) then
115 call this%free()
116 call this%allocate(source%size())
117 end if
118
119 call copy(this%x, source%x, this%n)
120
121 end subroutine host_array_assign
122
125 pure function host_array_size(this) result(n)
126 class(host_array_t), intent(in) :: this
127 integer :: n
128 n = this%n
129 end function host_array_size
130
133 pure function host_array_is_allocated(this) result(is_alloc)
134 class(host_array_t), intent(in) :: this
135 logical :: is_alloc
136
137 is_alloc = allocated(this%x)
138
139 end function host_array_is_allocated
140
141end module host_array
Module containing host-only array type.
subroutine host_array_assign(this, source)
Assignment with deep-copy ownership semantics.
subroutine host_array_allocate(this, size)
Allocate a host array (used by init and assignment).
subroutine host_array_free(this)
Free a host array.
pure integer function host_array_size(this)
Return the number of entries in the host array.
subroutine host_array_init(this, size)
Initialize a host array of size size.
pure logical function host_array_is_allocated(this)
Check whether the host array is allocated.
Definition math.f90:60
subroutine, public copy(a, b, n)
Copy a vector .
Definition math.f90:289
subroutine, public rzero(a, n)
Zero a real vector.
Definition math.f90:233
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Host-only temporary array.