Re: [petsc-users] Question-Memory of matsetvalue

2022-12-30 Thread Jed Brown
This is what I'd expect to observe if you didn't preallocate correctly for the 
second matrix, which has more nonzeros per row.

https://petsc.org/release/docs/manual/mat/#sec-matsparse

김성익  writes:

> Hello,
>
>
>
> I have a question about memory of matsetvalue.
>
> When I assembly the local matrix to global matrix, I’m just using
> matsetvalue.
> Because the connectivity is so complex I can’t use matsetvalues.
>
> I asked this question because I was curious about how ram memory is
> allocated differently for the two simtuations below.
>
>
>
> First situation.
>
> The local matrix size is 24 by 24. And the number of local matrix is
> 125,000.
>
> When assembly procedure by using matsetvalue, memory allocation does not
> increase.
> So I just put Matassemblybegin and matassemblyend after all matsetvalue.
>
>
>
> Second situation.
>
> The local matrix size is 60 by 60. And the number of local matrix is 27,000.
>
> When assembly procedure by using matsetvalue, memory allocation does
> increase.
>
> So I just put Matassemblybegin and matassemblyend after each local matrix
> assembly.
> This did not increase the memory further..
>
>
>
> Why this situation is happen?
>
> And is there any way to prevent the memory allocation from increasing?
>
>
>
>
>
>
>
> Thanks,
>
> Hyung Kim


Re: [petsc-users] Question-Memory of matsetvalue

2022-12-30 Thread Matthew Knepley
On Fri, Dec 30, 2022 at 4:36 AM 김성익  wrote:

> Hello,
>
>
>
> I have a question about memory of matsetvalue.
>
> When I assembly the local matrix to global matrix, I’m just using
> matsetvalue.
> Because the connectivity is so complex I can’t use matsetvalues.
>
> I asked this question because I was curious about how ram memory is
> allocated differently for the two simtuations below.
>
>
>
> First situation.
>
> The local matrix size is 24 by 24. And the number of local matrix is
> 125,000.
>
> When assembly procedure by using matsetvalue, memory allocation does not
> increase.
> So I just put Matassemblybegin and matassemblyend after all matsetvalue.
>
>
>
> Second situation.
>
> The local matrix size is 60 by 60. And the number of local matrix is
> 27,000.
>
> When assembly procedure by using matsetvalue, memory allocation does
> increase.
>
> So I just put Matassemblybegin and matassemblyend after each local matrix
> assembly.
> This did not increase the memory further..
>
>
>
> Why this situation is happen?
>
> And is there any way to prevent the memory allocation from increasing?
>

Matrix assembly has two stages. First you insert entries into the local
portion of your parallel matrix
using MatSetValue(s). If all values you try to insert are local, this is
the end.

However, if you try to insert values that are local to another process, we
store those values. When you
call MatAssemblyBegin/End(), we communicate them to the correct process and
insert.

For a scalable code, you should insert most values on the correct process.
If not, significant memory
can be consumed storing these values. Anywhere in the assembly process you
can call

  MatAssemblyBegin(A, MAT_ASSEMBLY_FLUSH);
  MatAssemblyEnd(A, MAT_ASSEMBLY_FLUSH);

This will communicate the cache of values, but not end the assembly.

   Thanks,

   Matt



> Thanks,
>
> Hyung Kim
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ 


[petsc-users] Question-Memory of matsetvalue

2022-12-30 Thread 김성익
Hello,



I have a question about memory of matsetvalue.

When I assembly the local matrix to global matrix, I’m just using
matsetvalue.
Because the connectivity is so complex I can’t use matsetvalues.

I asked this question because I was curious about how ram memory is
allocated differently for the two simtuations below.



First situation.

The local matrix size is 24 by 24. And the number of local matrix is
125,000.

When assembly procedure by using matsetvalue, memory allocation does not
increase.
So I just put Matassemblybegin and matassemblyend after all matsetvalue.



Second situation.

The local matrix size is 60 by 60. And the number of local matrix is 27,000.

When assembly procedure by using matsetvalue, memory allocation does
increase.

So I just put Matassemblybegin and matassemblyend after each local matrix
assembly.
This did not increase the memory further..



Why this situation is happen?

And is there any way to prevent the memory allocation from increasing?







Thanks,

Hyung Kim