Skip to content

Commit

Permalink
add zeroout!
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrKryslUCSD committed Mar 15, 2024
1 parent 32941b6 commit 3c1de7c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FinEtools"
uuid = "91bb5406-6c9a-523d-811d-0644c4229550"
authors = ["Petr Krysl <[email protected]>"]
version = "8.0.4"
version = "8.0.5"

[deps]
ChunkSplitters = "ae650224-84b6-46f8-82ea-d812ca08434e"
Expand Down
44 changes: 23 additions & 21 deletions src/AssemblyModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ expectedntriples(
n_elem_mats::IT,
) where {A<:AbstractSysmatAssembler, IT} = elem_mat_nrows * elem_mat_ncols * n_elem_mats

function _resize(self, chunk)
function _resize_buffers(self, chunk)
new_buffer_length = self._buffer_length + chunk
resize!(self._rowbuffer, new_buffer_length)
resize!(self._colbuffer, new_buffer_length)
resize!(self._matbuffer, new_buffer_length)
if self._force_init
self._rowbuffer[(self._buffer_length+1):end] .= 1
self._colbuffer[(self._buffer_length+1):end] .= 1
self._matbuffer[(self._buffer_length+1):end] .= 0
setvectorentries!(@view(self._rowbuffer[(self._buffer_length+1):end]), 1)
setvectorentries!(@view(self._colbuffer[(self._buffer_length+1):end]), 1)
setvectorentries!(@view(self._matbuffer[(self._buffer_length+1):end]), zero(eltype(self._matbuffer)))
end
self._buffer_length = new_buffer_length
return self
Expand Down Expand Up @@ -227,9 +227,9 @@ function startassembly!(
# Leave the buffers uninitialized, unless the user requests otherwise
self._force_init = force_init
if self._force_init
self._rowbuffer .= 1
self._colbuffer .= 1
self._matbuffer .= zero(T)
setvectorentries!(self._rowbuffer, 1)
setvectorentries!(self._colbuffer, 1)
setvectorentries!(self._matbuffer, zero(eltype(self._matbuffer)))
end
return self
end
Expand Down Expand Up @@ -257,7 +257,7 @@ function assemble!(
ncolumns = length(dofnums_col)
p = self._buffer_pointer
if self._buffer_length < p + ncolumns * nrows - 1
self = _resize(self, ncolumns * nrows * 1000)
self = _resize_buffers(self, ncolumns * nrows * 1000)
end
size(mat) == (nrows, ncolumns) || error("Wrong size of matrix")
@inbounds for j in 1:ncolumns
Expand Down Expand Up @@ -472,11 +472,11 @@ function startassembly!(
self._col_nalldofs = col_nalldofs
end
# Leave the buffers uninitialized, unless the user requests otherwise
self._force_init = force_init
if force_init
self._rowbuffer .= 1
self._colbuffer .= 1
self._matbuffer .= 0
self._force_init = force_init
setvectorentries!(self._rowbuffer, 1)
setvectorentries!(self._colbuffer, 1)
setvectorentries!(self._matbuffer, zero(eltype(self._matbuffer)))
end
return self
end
Expand Down Expand Up @@ -508,7 +508,7 @@ function assemble!(
@assert nrows == ncolumns
p = self._buffer_pointer
if self._buffer_length < p + (ncolumns * nrows + nrows) / 2 - 1
self = _resize(self, ncolumns * nrows * 1000)
self = _resize_buffers(self, ncolumns * nrows * 1000)
end
@assert size(mat) == (nrows, ncolumns)
@inbounds for j = 1:ncolumns
Expand Down Expand Up @@ -694,10 +694,11 @@ function startassembly!(
self._col_nalldofs = col_nalldofs
end
# Leave the buffers uninitialized, unless the user requests otherwise
self._force_init = force_init
if force_init
self._rowbuffer .= 1
self._colbuffer .= 1
self._matbuffer .= 0
setvectorentries!(self._rowbuffer, 1)
setvectorentries!(self._colbuffer, 1)
setvectorentries!(self._matbuffer, zero(eltype(self._matbuffer)))
end
return self
end
Expand Down Expand Up @@ -730,7 +731,7 @@ function assemble!(
@assert nrows == ncolumns
p = self._buffer_pointer
if self._buffer_length < p + ncolumns * nrows - 1
self = _resize(self, ncolumns * nrows * 1000)
self = _resize_buffers(self, ncolumns * nrows * 1000)
end
@assert size(mat) == (nrows, ncolumns)
@inbounds for j = 1:ncolumns
Expand Down Expand Up @@ -1036,10 +1037,11 @@ function startassembly!(
self._col_nalldofs = col_nalldofs
end
# Leave the buffers uninitialized, unless the user requests otherwise
self._force_init = force_init
if force_init
self._rowbuffer .= 1
self._colbuffer .= 1
self._matbuffer .= 0
setvectorentries!(self._rowbuffer, 1)
setvectorentries!(self._colbuffer, 1)
setvectorentries!(self._matbuffer, zero(eltype(self._matbuffer)))
end
return self
end
Expand Down Expand Up @@ -1069,7 +1071,7 @@ function assemble!(
@assert nrows == ncolumns
p = self._buffer_pointer
if self._buffer_length < p + ncolumns * nrows - 1
self = _resize(self, ncolumns * nrows * 1000)
self = _resize_buffers(self, ncolumns * nrows * 1000)
end
@assert size(mat) == (nrows, ncolumns)
# Now comes the lumping procedure
Expand Down
2 changes: 2 additions & 0 deletions src/FinEtools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -643,5 +643,7 @@ using .MatrixUtilityModule:
export matrix_blocked_ff, matrix_blocked_fd, matrix_blocked_df, matrix_blocked_dd
using .MatrixUtilityModule: vector_blocked_f, vector_blocked_d
export vector_blocked_f, vector_blocked_d
using .MatrixUtilityModule: setvectorentries!
export setvectorentries!

end
15 changes: 15 additions & 0 deletions src/MatrixUtilityModule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -838,4 +838,19 @@ function vector_blocked_d(V, nfreedofs)
return V_d
end

"""
setvectorentries!(a, v = zero(eltype(a)))
Set entries of a long vector to a given constant.
The operation runs in parallel on as many threads as are available.
"""
function setvectorentries!(a, v = zero(eltype(a)))
@inbounds Threads.@threads for k in eachindex(a)
a[k] = v
end
a
end


end

2 comments on commit 3c1de7c

@PetrKryslUCSD
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/102901

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v8.0.5 -m "<description of version>" 3c1de7cb15f17986a1d11db7ec2341612274788e
git push origin v8.0.5

Please sign in to comment.