<div dir="ltr">Hi,<div><br></div><div>I'm having trouble setting all entries of a matrix to a constant value, similar to the `VecSet` method on vectors. I have a dense matrix that I want to initialize all entries to 1. The only related method I see on the `Mat` interface is `MatZeroEntries`, which sets all entries to 0. The obvious first attempt is to use the `MatSetValue` function to set all entries to the constant.</div><div><br></div><div>```</div><div> Mat C;</div><div>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue""><span class="gmail-Apple-converted-space"> </span>MatCreateDense(PETSC_COMM_WORLD, PETSC_DECIDE, PETSC_DECIDE, k, j, NULL, &C);</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue""><span class="gmail-Apple-converted-space"> </span>for (int kk = 0; kk < k; kk++) {<br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue""><span class="gmail-Apple-converted-space"> </span>for (int jj = 0; jj < j; jj++) {</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue""><span class="gmail-Apple-converted-space"> </span>MatSetValue(C, kk, jj, 1, INSERT_VALUES);</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue""><span class="gmail-Apple-converted-space"> </span>}</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue""><span class="gmail-Apple-converted-space"> </span>}</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue""><span class="gmail-Apple-converted-space"> </span>MatAssemblyBegin(C, MAT_FINAL_ASSEMBLY);</p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:12px;line-height:normal;font-family:"Helvetica Neue""><span class="gmail-Apple-converted-space"> </span>MatAssemblyEnd(C, MAT_FINAL_ASSEMBLY);</p></div><div>```</div><div><br></div><div>However, when run with a relatively large matrix C (5GB) and a rank-per-core on my 40-core machine this code OOMs and crashes. It does not OOM with only 1 and 10 rank, leading me to believe that this API call is somehow causing the entire matrix to be replicated on each rank.</div><div><br></div><div>Despite looking through the documentation, I could not find another API call that would allow me to set all the values in the matrix to a constant. What should I do here?</div><div><br></div><div>Thanks,</div><div><br></div><div>Rohan</div></div>