<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On 13 Jun 2025, at 11:32 AM, SCOTTO Alexandre via petsc-users <petsc-users@mcs.anl.gov> wrote:</div><br class="Apple-interchange-newline"><div><meta charset="UTF-8"><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="FR">Dear PETSc community,<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><span lang="FR"><o:p> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">I am currently struggling with the ADD_VALUE mode of the Scatter object. Here is a simple piece of (Python) code to illustrate the issue:<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; line-height: 12pt; background: rgb(31, 31, 31);"><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">vec_1</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(212, 212, 212);">=</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(78, 201, 176);">PETSc</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">.Vec().createMPI(</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">size</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(212, 212, 212);">=</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(181, 206, 168);">10</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">)<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; line-height: 12pt; background: rgb(31, 31, 31);"><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">vec_1</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">.shift(</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(181, 206, 168);">2.0</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">)<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; line-height: 12pt; background: rgb(31, 31, 31);"><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><o:p> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; line-height: 12pt; background: rgb(31, 31, 31);"><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">vec_2</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(212, 212, 212);">=</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(78, 201, 176);">PETSc</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">.Vec().createMPI(</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">size</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(212, 212, 212);">=</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(181, 206, 168);">10</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">)<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; line-height: 12pt; background: rgb(31, 31, 31);"><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">vec_2</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">.shift(</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(181, 206, 168);">1.0</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">)<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; line-height: 12pt; background: rgb(31, 31, 31);"><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><o:p> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; line-height: 12pt; background: rgb(31, 31, 31);"><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">index_set</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(212, 212, 212);">=</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(78, 201, 176);">PETSc</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">.IS().createStride(</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(181, 206, 168);">10</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">,<span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">step</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(212, 212, 212);">=</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(181, 206, 168);">1</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">)<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; line-height: 12pt; background: rgb(31, 31, 31);"><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><o:p> </o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; line-height: 12pt; background: rgb(31, 31, 31);"><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">scatter</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(212, 212, 212);">=</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);"><span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(78, 201, 176);">PETSc</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">.Scatter().create(</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">vec_1</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">,<span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">index_set</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">,<span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">vec_2</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">,<span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">index_set</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">)<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif; line-height: 12pt; background: rgb(31, 31, 31);"><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">scatter</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">.scatter(</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">vec_1</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">,<span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">vec_2</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">,<span class="Apple-converted-space"> </span></span><span style="font-size: 9pt; font-family: Consolas; color: rgb(156, 220, 254);">addv</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(212, 212, 212);">=</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(86, 156, 214);">True</span><span style="font-size: 9pt; font-family: Consolas; color: rgb(204, 204, 204);">)<o:p></o:p></span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Vectors vec_1 and vec_2 are respectively filled-in with 2.0 and 1.0. After the scattering, I would expect to have in vec_2 the sum of the values initially in vec_2 (that is 1.0) plus the values coming from vec_1 (that is 2.0).<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">But instead of having vec_2 filled in with 3.0 it is filled-in with 9.0. My understanding is that the number of processes (here 4 processes) plays a role since 9.0 = 1.0 (initial value) + 2.0 (values coming from vec_1) x 4 (number of processes).<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p> </o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Is there a way to have simply 3.0 as a result?</div></div></div></blockquote><div><br></div><div>With the index_set you are supplying, you are basically saying that each process should scatter the complete vector (not just its local portion).</div><div>If you use an index_set which does not induce communication (e.g., of size the local size of the Vec and with the same start as the first local row of the Vec), then you’ll get 3.0 as a result.</div><div><br></div><div>Thanks,</div><div>Pierre</div><br><blockquote type="cite"><div><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Hoping to have been clear enough, best regards,<o:p></o:p></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Alexandre.</div></div></div></blockquote></div><br></body></html>