Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tnl-dev
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
TNL
tnl-dev
Merge requests
!141
An error occurred while fetching the assigned milestone of the selected merge_request.
Added sequential LU factorization from tnl-mhfem
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Added sequential LU factorization from tnl-mhfem
JK/LU
into
develop
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
Jakub Klinkovský
requested to merge
JK/LU
into
develop
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Viewing commit
1968a6aa
Show latest version
1 file
+
83
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
1968a6aa
Added sequential LU factorization from tnl-mhfem
· 1968a6aa
Jakub Klinkovský
authored
2 years ago
src/TNL/Matrices/Factorization/LUsequential.h
0 → 100644
+
83
−
0
Options
// Copyright (c) 2004-2022 Tomáš Oberhuber et al.
//
// This file is part of TNL - Template Numerical Library (https://tnl-project.org/)
//
// SPDX-License-Identifier: MIT
// Implemented by: Jakub Klinkovský
#pragma once
#include
<TNL/Assert.h>
#include
<TNL/Cuda/CudaCallable.h>
namespace
TNL
{
namespace
Matrices
{
namespace
Factorization
{
template
<
typename
Matrix
>
__cuda_callable__
void
LU_sequential_factorize
(
Matrix
&
A
)
{
using
IndexType
=
typename
Matrix
::
IndexType
;
static_assert
(
Matrix
::
getRows
()
==
Matrix
::
getColumns
(),
"LU factorization is possible only for square matrices"
);
constexpr
IndexType
n
=
Matrix
::
getRows
();
for
(
IndexType
k
=
0
;
k
<
n
;
k
++
)
{
const
auto
pivot
=
A
(
k
,
k
);
// Update the (k+1 .. n-1)-th rows
for
(
IndexType
j
=
k
+
1
;
j
<
n
;
j
++
)
{
const
auto
factor
=
A
(
j
,
k
)
/
pivot
;
// Update elements of k-th column below pivot (i.e. elements of L)
A
(
j
,
k
)
=
factor
;
// Subtract k-th row from j-th
for
(
IndexType
i
=
k
+
1
;
i
<
n
;
i
++
)
{
A
(
j
,
i
)
=
A
(
j
,
i
)
-
factor
*
A
(
k
,
i
);
}
}
}
}
template
<
typename
Matrix
,
typename
Vector
>
__cuda_callable__
void
LU_sequential_solve_inplace
(
const
Matrix
&
A
,
Vector
&
x
)
{
using
IndexType
=
typename
Matrix
::
IndexType
;
static_assert
(
std
::
is_signed
<
IndexType
>::
value
,
"LU got a matrix with an unsigned index type (2nd for loop won't work)"
);
static_assert
(
Matrix
::
getRows
()
==
Matrix
::
getColumns
(),
"LU factorization is possible only for square matrices"
);
constexpr
IndexType
n
=
Matrix
::
getRows
();
// Forward substitution
for
(
IndexType
k
=
1
;
k
<
n
;
k
++
)
for
(
IndexType
j
=
0
;
j
<
k
;
j
++
)
x
[
k
]
-=
A
(
k
,
j
)
*
x
[
j
];
// Back substitution
for
(
IndexType
k
=
n
-
1
;
k
>=
0
;
k
--
)
{
for
(
IndexType
j
=
n
-
1
;
j
>
k
;
j
--
)
x
[
k
]
-=
A
(
k
,
j
)
*
x
[
j
];
x
[
k
]
/=
A
(
k
,
k
);
}
}
template
<
typename
Matrix
,
typename
Vector1
,
typename
Vector2
>
__cuda_callable__
void
LU_sequential_solve
(
const
Matrix
&
A
,
const
Vector1
&
b
,
Vector2
&
x
)
{
// Copy right hand side
x
=
b
;
// Solve in-place
LU_sequential_solve_inplace
(
A
,
x
);
}
}
// namespace Factorization
}
// namespace Matrices
}
// namespace TNL
Loading