Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gmsh
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry Price
gmsh
Commits
17f6e571
Commit
17f6e571
authored
14 years ago
by
Jonathan Lambrechts
Browse files
Options
Downloads
Patches
Plain Diff
Solver : linearSystemCSR : reduced peak memory (and remove potential
memory leak)
parent
5eae401e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Solver/linearSystemCSR.cpp
+14
-12
14 additions, 12 deletions
Solver/linearSystemCSR.cpp
with
14 additions
and
12 deletions
Solver/linearSystemCSR.cpp
+
14
−
12
View file @
17f6e571
...
@@ -24,9 +24,7 @@ static void *CSRMalloc(size_t size)
...
@@ -24,9 +24,7 @@ static void *CSRMalloc(size_t size)
static
void
*
CSRRealloc
(
void
*
ptr
,
size_t
size
)
static
void
*
CSRRealloc
(
void
*
ptr
,
size_t
size
)
{
{
if
(
!
size
)
return
(
NULL
);
return
realloc
(
ptr
,
size
);
ptr
=
realloc
(
ptr
,
size
);
return
(
ptr
);
}
}
static
void
CSRList_Realloc
(
CSRList_T
*
liste
,
int
n
)
static
void
CSRList_Realloc
(
CSRList_T
*
liste
,
int
n
)
...
@@ -46,10 +44,11 @@ static void CSRList_Realloc(CSRList_T *liste, int n)
...
@@ -46,10 +44,11 @@ static void CSRList_Realloc(CSRList_T *liste, int n)
}
}
}
}
static
void
CSRList_Resize
(
CSRList_T
*
liste
,
int
n
)
static
void
CSRList_Resize
_strict
(
CSRList_T
*
liste
,
int
n
)
{
{
CSRList_Realloc
(
liste
,
n
);
liste
->
array
=
(
char
*
)
CSRRealloc
(
liste
->
array
,
n
*
liste
->
size
);
liste
->
n
=
n
;
liste
->
n
=
n
;
liste
->
nmax
=
n
;
}
}
static
CSRList_T
*
CSRList_Create
(
int
n
,
int
incr
,
int
size
)
static
CSRList_T
*
CSRList_Create
(
int
n
,
int
incr
,
int
size
)
...
@@ -105,13 +104,11 @@ void linearSystemCSR<double>::preAllocateEntries ()
...
@@ -105,13 +104,11 @@ void linearSystemCSR<double>::preAllocateEntries ()
_sparsity
.
getRow
(
i
,
nInRow
);
_sparsity
.
getRow
(
i
,
nInRow
);
nnz
+=
nInRow
;
nnz
+=
nInRow
;
}
}
CSRList_Resize
(
_a
,
nnz
);
CSRList_Resize_strict
(
_ai
,
nnz
);
CSRList_Resize
(
_ai
,
nnz
);
CSRList_Resize_strict
(
_ptr
,
nnz
);
CSRList_Resize
(
_ptr
,
nnz
);
INDEX_TYPE
*
jptr
=
(
INDEX_TYPE
*
)
_jptr
->
array
;
INDEX_TYPE
*
jptr
=
(
INDEX_TYPE
*
)
_jptr
->
array
;
INDEX_TYPE
*
ai
=
(
INDEX_TYPE
*
)
_ai
->
array
;
INDEX_TYPE
*
ai
=
(
INDEX_TYPE
*
)
_ai
->
array
;
INDEX_TYPE
*
ptr
=
(
INDEX_TYPE
*
)
_ptr
->
array
;
INDEX_TYPE
*
ptr
=
(
INDEX_TYPE
*
)
_ptr
->
array
;
double
*
a
=
(
double
*
)
_a
->
array
;
jptr
[
0
]
=
0
;
jptr
[
0
]
=
0
;
nnz
=
0
;
nnz
=
0
;
for
(
int
i
=
0
;
i
<
nbRows
;
i
++
){
for
(
int
i
=
0
;
i
<
nbRows
;
i
++
){
...
@@ -119,18 +116,23 @@ void linearSystemCSR<double>::preAllocateEntries ()
...
@@ -119,18 +116,23 @@ void linearSystemCSR<double>::preAllocateEntries ()
const
int
*
row
=
_sparsity
.
getRow
(
i
,
nInRow
);
const
int
*
row
=
_sparsity
.
getRow
(
i
,
nInRow
);
for
(
int
j
=
0
;
j
<
nInRow
;
j
++
)
{
for
(
int
j
=
0
;
j
<
nInRow
;
j
++
)
{
ai
[
nnz
]
=
row
[
j
];
ai
[
nnz
]
=
row
[
j
];
a
[
nnz
]
=
0.
;
ptr
[
nnz
]
=
nnz
+
1
;
ptr
[
nnz
]
=
nnz
+
1
;
nnz
++
;
nnz
++
;
}
}
if
(
nInRow
!=
0
)
if
(
nInRow
!=
0
)
ptr
[
nnz
-
1
]
=
0
;
ptr
[
nnz
-
1
]
=
0
;
jptr
[
i
+
1
]
=
nnz
;
jptr
[
i
+
1
]
=
nnz
;
something
[
i
]
=
(
nInRow
==
0
?
0
:
1
);
something
[
i
]
=
(
nInRow
==
0
?
0
:
1
);
}
}
_entriesPreAllocated
=
true
;
_entriesPreAllocated
=
true
;
sorted
=
true
;
sorted
=
true
;
_sparsity
.
clear
();
_sparsity
.
clear
();
// we do this after _sparsity.clear so that the peak memory usage is reduced
CSRList_Resize_strict
(
_a
,
nnz
);
double
*
a
=
(
double
*
)
_a
->
array
;
for
(
int
i
=
0
;
i
<
nnz
;
i
++
)
{
a
[
i
]
=
0.
;
}
}
}
template
<
>
template
<
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment