[petsc-users] MatCreateSeqDense

Barry Smith bsmith at mcs.anl.gov
Thu Jan 28 18:26:45 CST 2016


> On Jan 28, 2016, at 6:23 PM, Bhalla, Amneet Pal S <amneetb at live.unc.edu> wrote:
> 
> Thanks!
> 
> Another related question: If I do something like this:
> 
> double* data;
> 
> // do stuff with data
> data[i] = ...
> 
> Mat A;
> MatCreateSeqDense(...,data,..., &A);
> 
> // do more stuff with data
> data[i] = ..
> 
> Now would the matrix A reflect the change (i.e updated A[i][j]) without making an explicit call to PetscObjectStateIncrease((PetscObject)A)?

   The values in the matrix will be different but the matrix object will not know you have changed anything and hence strange stuff might happen.

   We highly recommend that after you have created the matrix you do not use the data[] array anymore. Instead call MatDenseGetArray() change stuff MatDenseRestoreArray() this automatically increases the matrix state and is cleaner code anyways (calling MatDenseGetArray() is super fast because it only gets the pointer you already provided).

   Barry

> 
> 
>> On Jan 28, 2016, at 3:06 PM, Matthew Knepley <knepley at gmail.com> wrote:
>> 
>> On Thu, Jan 28, 2016 at 4:53 PM, Bhalla, Amneet Pal S <amneetb at live.unc.edu> wrote:
>> Hi Folks,
>> 
>> Is there a way to get back the user allocated raw data pointer (column-major order) used in creating MatCreateSeqDense() from the Mat object?
>> 
>> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatDenseGetArray.html
>> 
>>    Matt
>>  
>> Thanks,
>> --Amneet
>> 
>> 
>> 
>> -- 
>> 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
> 



More information about the petsc-users mailing list