Re: [petsc-users] a question about MatSetValue

2020-05-21 Thread Yang Bo (Asst Prof)
I see, it is working now, thanks!

On 21 May 2020, at 6:23 PM, Dave May 
mailto:dave.mayhe...@gmail.com>> wrote:



On Thu 21. May 2020 at 12:17, Yang Bo (Asst Prof) 
mailto:yang...@ntu.edu.sg>> wrote:
Hi Dave,

Yes it is parallel so the preallocation calls are not lowered by the allocation.

I am trying to use MatXAIJSetPreallocation, but not sure how, since the 
following link does not give an example:

https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatXAIJSetPreallocation.html

If I have the following matrix:

0 1 2 0
1 0 0 0
2 0 1 3
0 0 3 2

How should I put in the parameters of MatXAIJSetPreallocation?

Please read this page to understand the info required

https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html


Compute everything as described above and give the results to 
MatXAIJSetPreallocation(). MatXAIJSetPreallocation() is just a helper function 
to hide all the implementation specific setters.

Thanks
Dave






Thanks!

Cheers,

Yang Bo


On 21 May 2020, at 5:42 PM, Dave May 
mailto:dave.mayhe...@gmail.com>> wrote:



On Thu 21. May 2020 at 10:49, Yang Bo (Asst Prof) 
mailto:yang...@ntu.edu.sg>> wrote:
Hi Dave,

Thank you very much for your reply. That is indeed the problem. I have been 
working with matrices in Slepc but I don’t really understand it. I tried to 
preallocate but it still does not work.

Meaning the number of reported mallocs is still non-zero?
Is the number reported with you preallocation calls lower than what you 
originally saw?

If you look at my code below:

ierr = MatCreate(PETSC_COMM_WORLD,);CHKERRQ(ierr);
ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,h_dim,h_dim);
  // h_dim is the dimension of the square matrix A
ierr = MatSetFromOptions(A);CHKERRQ(ierr);
ierr = MatSetUp(A);CHKERRQ(ierr);
ierr = MatGetOwnershipRange(A,,);CHKERRQ(ierr);

MatSeqAIJSetPreallocation(A,0,nnz);   // I 
try to preallocate here, where nnz is the array containing the number of 
non-zero entries each row

for (int i=0;imailto:dave.mayhe...@gmail.com>> wrote:

-info | grep malloc



CONFIDENTIALITY: This email is intended solely for the person(s) named and may 
be confidential and/or privileged. If you are not the intended recipient, 
please delete it, notify us and do not copy, use, or disclose its contents.
Towards a sustainable earth: Print only when necessary. Thank you.



Re: [petsc-users] a question about MatSetValue

2020-05-21 Thread Dave May
On Thu 21. May 2020 at 12:17, Yang Bo (Asst Prof) 
wrote:

> Hi Dave,
>
> Yes it is parallel so the preallocation calls are not lowered by the
> allocation.
>
> I am trying to use MatXAIJSetPreallocation, but not sure how, since the
> following link does not give an example:
>
>
> https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatXAIJSetPreallocation.html
>
> If I have the following matrix:
>
> 0 1 2 0
> 1 0 0 0
> 2 0 1 3
> 0 0 3 2
>
> How should I put in the parameters of MatXAIJSetPreallocation?
>

Please read this page to understand the info required

https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html


Compute everything as described above and give the results to
MatXAIJSetPreallocation(). MatXAIJSetPreallocation() is just a helper
function to hide all the implementation specific setters.

Thanks
Dave






> Thanks!
>
> Cheers,
>
> Yang Bo
>
>
> On 21 May 2020, at 5:42 PM, Dave May  wrote:
>
>
>
> On Thu 21. May 2020 at 10:49, Yang Bo (Asst Prof) 
> wrote:
>
>> Hi Dave,
>>
>> Thank you very much for your reply. That is indeed the problem. I have
>> been working with matrices in Slepc but I don’t really understand it. I
>> tried to preallocate but it still does not work.
>>
>
> Meaning the number of reported mallocs is still non-zero?
> Is the number reported with you preallocation calls lower than what you
> originally saw?
>
> If you look at my code below:
>>
>> ierr = MatCreate(PETSC_COMM_WORLD,);CHKERRQ(ierr);
>> ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,h_dim,h_dim);
>>  // h_dim is the dimension of the square matrix A
>> ierr = MatSetFromOptions(A);CHKERRQ(ierr);
>> ierr = MatSetUp(A);CHKERRQ(ierr);
>> ierr = MatGetOwnershipRange(A,,);CHKERRQ(ierr);
>>
>> MatSeqAIJSetPreallocation(A,0,nnz);
>>  // I try to preallocate here, where nnz is the array containing the
>> number of non-zero entries each row
>>
>> for (int i=0;i> MatSetValue(A,row[i],column[i],h[i],INSERT_VALUES);
>> }
>>
>> I am not sure what other information I need to give for the
>> pre-allocation…
>>
>
> This looks fine. However MatSeqAIJSetPreallocation() has no effect if the
> Mat type is not SEQAIJ.
>
> Are you running in parallel? If yes then the Mat type will be MATMPIAIJ
> and you either have to call the MPI specific preallocator or use the
> generic one I pointed you too.
>
> Thanks
> Dave
>
>
>
>> Cheers,
>>
>> Yang Bo
>>
>>
>>
>> On 21 May 2020, at 4:08 PM, Dave May  wrote:
>>
>> *-info | grep malloc*
>>
>>
>> --
>>
>> CONFIDENTIALITY: This email is intended solely for the person(s) named
>> and may be confidential and/or privileged. If you are not the intended
>> recipient, please delete it, notify us and do not copy, use, or disclose
>> its contents.
>> Towards a sustainable earth: Print only when necessary. Thank you.
>>
>
>


Re: [petsc-users] a question about MatSetValue

2020-05-21 Thread Yang Bo (Asst Prof)
Hi Dave,

Yes it is parallel so the preallocation calls are not lowered by the allocation.

I am trying to use MatXAIJSetPreallocation, but not sure how, since the 
following link does not give an example:

https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatXAIJSetPreallocation.html

If I have the following matrix:

0 1 2 0
1 0 0 0
2 0 1 3
0 0 3 2

How should I put in the parameters of MatXAIJSetPreallocation?

Thanks!

Cheers,

Yang Bo


On 21 May 2020, at 5:42 PM, Dave May 
mailto:dave.mayhe...@gmail.com>> wrote:



On Thu 21. May 2020 at 10:49, Yang Bo (Asst Prof) 
mailto:yang...@ntu.edu.sg>> wrote:
Hi Dave,

Thank you very much for your reply. That is indeed the problem. I have been 
working with matrices in Slepc but I don’t really understand it. I tried to 
preallocate but it still does not work.

Meaning the number of reported mallocs is still non-zero?
Is the number reported with you preallocation calls lower than what you 
originally saw?

If you look at my code below:

ierr = MatCreate(PETSC_COMM_WORLD,);CHKERRQ(ierr);
ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,h_dim,h_dim);
  // h_dim is the dimension of the square matrix A
ierr = MatSetFromOptions(A);CHKERRQ(ierr);
ierr = MatSetUp(A);CHKERRQ(ierr);
ierr = MatGetOwnershipRange(A,,);CHKERRQ(ierr);

MatSeqAIJSetPreallocation(A,0,nnz);   // I 
try to preallocate here, where nnz is the array containing the number of 
non-zero entries each row

for (int i=0;imailto:dave.mayhe...@gmail.com>> wrote:

-info | grep malloc



CONFIDENTIALITY: This email is intended solely for the person(s) named and may 
be confidential and/or privileged. If you are not the intended recipient, 
please delete it, notify us and do not copy, use, or disclose its contents.
Towards a sustainable earth: Print only when necessary. Thank you.



Re: [petsc-users] a question about MatSetValue

2020-05-21 Thread Dave May
On Thu 21. May 2020 at 10:49, Yang Bo (Asst Prof) 
wrote:

> Hi Dave,
>
> Thank you very much for your reply. That is indeed the problem. I have
> been working with matrices in Slepc but I don’t really understand it. I
> tried to preallocate but it still does not work.
>

Meaning the number of reported mallocs is still non-zero?
Is the number reported with you preallocation calls lower than what you
originally saw?

If you look at my code below:
>
> ierr = MatCreate(PETSC_COMM_WORLD,);CHKERRQ(ierr);
> ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,h_dim,h_dim);
>  // h_dim is the dimension of the square matrix A
> ierr = MatSetFromOptions(A);CHKERRQ(ierr);
> ierr = MatSetUp(A);CHKERRQ(ierr);
> ierr = MatGetOwnershipRange(A,,);CHKERRQ(ierr);
>
> MatSeqAIJSetPreallocation(A,0,nnz);   //
> I try to preallocate here, where nnz is the array containing the number of
> non-zero entries each row
>
> for (int i=0;i MatSetValue(A,row[i],column[i],h[i],INSERT_VALUES);
> }
>
> I am not sure what other information I need to give for the pre-allocation…
>

This looks fine. However MatSeqAIJSetPreallocation() has no effect if the
Mat type is not SEQAIJ.

Are you running in parallel? If yes then the Mat type will be MATMPIAIJ and
you either have to call the MPI specific preallocator or use the generic
one I pointed you too.

Thanks
Dave



> Cheers,
>
> Yang Bo
>
>
>
> On 21 May 2020, at 4:08 PM, Dave May  wrote:
>
> *-info | grep malloc*
>
>
> --
>
> CONFIDENTIALITY: This email is intended solely for the person(s) named and
> may be confidential and/or privileged. If you are not the intended
> recipient, please delete it, notify us and do not copy, use, or disclose
> its contents.
> Towards a sustainable earth: Print only when necessary. Thank you.
>


Re: [petsc-users] a question about MatSetValue

2020-05-21 Thread Yang Bo (Asst Prof)
Hi Dave,

Thank you very much for your reply. That is indeed the problem. I have been 
working with matrices in Slepc but I don’t really understand it. I tried to 
preallocate but it still does not work. If you look at my code below:

ierr = MatCreate(PETSC_COMM_WORLD,);CHKERRQ(ierr);
ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,h_dim,h_dim);
  // h_dim is the dimension of the square matrix A
ierr = MatSetFromOptions(A);CHKERRQ(ierr);
ierr = MatSetUp(A);CHKERRQ(ierr);
ierr = MatGetOwnershipRange(A,,);CHKERRQ(ierr);

MatSeqAIJSetPreallocation(A,0,nnz);   // I 
try to preallocate here, where nnz is the array containing the number of 
non-zero entries each row

for (int i=0;imailto:dave.mayhe...@gmail.com>> wrote:

-info | grep malloc



CONFIDENTIALITY: This email is intended solely for the person(s) named and may 
be confidential and/or privileged. If you are not the intended recipient, 
please delete it, notify us and do not copy, use, or disclose its contents.
Towards a sustainable earth: Print only when necessary. Thank you.


Re: [petsc-users] a question about MatSetValue

2020-05-21 Thread Dave May
On Thu, 21 May 2020 at 08:55, Yang Bo (Asst Prof) 
wrote:

> Hi Everyone,
>
> I have a question about adding values to the matrix. The code I have is
>
>
> for (int i=0;i MatSetValue(A,row[i],column[i],h[i],INSERT_VALUES);
> }
>
> where row.size() is a large number. It seems the running time of this
> procedure does not scale linearly with row.size(). As row.size() gets
> bigger, the time it takes increases exponentially.


It sounds like your matrix is not properly preallocated. Could this be the
case?

You can confirm / deny this by running with the command line options (shown
in bold)

./your-exec * -info | grep malloc*

If all is good you will see something like this

[0] MatAssemblyEnd_SeqAIJ(): Number of mallocs during MatSetValues() is 0
*total number of mallocs used during MatSetValues calls=0*

If the reported number of mallocs in your code is not 0, please read these
pages:

https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSeqAIJSetPreallocation.html

https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html


You may like to use the generic preallocator (depending on the type of you
Mat).

https://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatXAIJSetPreallocation.html


Thanks
Dave




> Am I doing something wrong and can I do better than that?
>
> Thanks and stay healthy!
>
> Cheers,
>
> Yang Bo
> 
>
> CONFIDENTIALITY: This email is intended solely for the person(s) named and
> may be confidential and/or privileged. If you are not the intended
> recipient, please delete it, notify us and do not copy, use, or disclose
> its contents.
> Towards a sustainable earth: Print only when necessary. Thank you.
>


[petsc-users] a question about MatSetValue

2020-05-21 Thread Yang Bo (Asst Prof)
Hi Everyone,

I have a question about adding values to the matrix. The code I have is


for (int i=0;i