<html><body><div style="font-family: times new roman, new york, times, serif; font-size: 12pt; color: #000000"><div>Stefano, I've realized you are right, and that, unfortunately the initial problem is not solved...<br></div><div><br></div><div>In the target code I work on, MatIS is created this way:<br></div><div>MatCreateIS(..., rmap, cmap, ...)</div><div>MatISSetLocalMat()</div><div>MatAssemblyBegin/End()</div><div>Note that I do not use MatSetValues directly on the MatIS (I do it on local matrices only). Also, I do not call MatSetLocalToGlobalMapping (as you said Stefano, it's done in MatCreateIS).<br></div><div><br></div><div>On my target code, when trying to MatView a MatIS in binary format, I got this error (note that ASCII and matlab are OK):</div><div> [0]PETSC ERROR: No support for this operation for this object type<br>[0]PETSC ERROR: Cannot get subcomm viewer for binary files or sockets unless SubViewer contains the rank 0 process<br><br>Googling this lead me to <a href="https://lists.mcs.anl.gov/mailman/htdig/petsc-users/2016-September/030438.html,">https://lists.mcs.anl.gov/mailman/htdig/petsc-users/2016-September/030438.html,</a> from where I restarted hoping to get a reduced toy/minimal problem (this example uses MatCreate+MatSetType but not MatCreateIS as I use it in the target code: I realized this slight difference after I sent the mail).<br><br></div><div>When Pierre replied, I was in a rush... And tested the wrong command line (!) : I believed the problem was solved... It's unfortunately not !<br></div><div><br></div><div>In the toy example I added MatSetLocalToGlobalMapping and MatISSetLocalMat, as you can see:<br></div><div><br></div><div>>> more matExport.cpp <br>/*<br> * mpirun -n 2 ./matExport.exe<br> * mpirun -n 2 ./matExport.exe is<br> */<br><br>#include <petscmat.h><br>#include <petscsys.h><br>#include <string.h><br><br>int main(int argc, char *argv[])<br>{<br> PetscInitialize(&argc, &argv, "", NULL);<br><br> Mat matrix;<br> MatCreate(PETSC_COMM_WORLD, &matrix);<br> const char* matType = (argc >= 2) ? argv[1] : MATMPIAIJ;<br> PetscPrintf(PETSC_COMM_WORLD, "mat type is %s \n", matType);<br> MatSetType(matrix, matType);<br> MatSetSizes(matrix, PETSC_DECIDE, PETSC_DECIDE, 10, 10);<br> if (strcmp(matType, "is") == 0) {<br> ISLocalToGlobalMapping is;<br> PetscInt idx[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};<br> ISLocalToGlobalMappingCreate(PETSC_COMM_WORLD, 1, 10, idx, PETSC_COPY_VALUES, &is);<br> MatSetLocalToGlobalMapping(matrix, is, is);<br> ISLocalToGlobalMappingDestroy(&is);<br> PetscPrintf(PETSC_COMM_WORLD, "MatSetLocalToGlobalMapping done\n");<br><br> Mat local;<br> MatCreateSeqDense(PETSC_COMM_SELF, 10, 10, NULL, &local);<br> for (int i = 0; i < 10; i++) MatSetValue(local, i, i, (double)(i+1.), ADD_VALUES);<br> MatAssemblyBegin(local, MAT_FINAL_ASSEMBLY); MatAssemblyBegin(local, MAT_FINAL_ASSEMBLY);<br> MatISSetLocalMat(matrix, local);<br> MatDestroy(&local);<br> }<br> else {<br> MatSetUp(matrix);<br> for (int i = 0; i < 10; i++) MatSetValue(matrix, i, i, (double)(i+1.), ADD_VALUES);<br> }<br> MatAssemblyBegin(matrix, MAT_FINAL_ASSEMBLY);<br> MatAssemblyEnd(matrix, MAT_FINAL_ASSEMBLY);<br><br> PetscViewer viewer;<br> PetscViewerBinaryOpen(PETSC_COMM_WORLD, "matExport.bin", FILE_MODE_WRITE, &viewer);<br> MatView(matrix, viewer);<br> PetscViewerDestroy(&viewer);<br><br> PetscViewerASCIIOpen(PETSC_COMM_WORLD, "matExport.log", &viewer);<br> MatView(matrix, viewer);<br> PetscViewerDestroy(&viewer);<br><br> PetscViewerASCIIOpen(PETSC_COMM_WORLD, "matExport.mat", &viewer);<br> PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);<br> MatView(matrix, viewer);<br> PetscViewerDestroy(&viewer);<br><br> MatDestroy(&matrix);<br> PetscFinalize();<br>}<br></div><div><br></div><div>MPIAIJ is still OK:</div><div><br>>> mpirun -n 2 ./matExport.exe<br>mat type is mpiaij <br></div><div><br></div><div>MATIS is still KO :<br></div><div><br></div><div>>> mpirun -n 2 ./matExport.exe is<br>mat type is is <br>MatSetLocalToGlobalMapping done<br>[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br>[0]PETSC ERROR: No support for this operation for this object type<br>[0]PETSC ERROR: Cannot get subcomm viewer for binary files or sockets unless SubViewer contains the rank 0 process<br>[0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for trouble shooting.<br><br></div><div>From gdb I got this stack (still need to recompile in debug tomorrow - I won't have time tonight)<br></div><div><br></div><div>#0 0x00007ff47bdb466d in nanosleep () at ../sysdeps/unix/syscall-template.S:84<br>#1 0x00007ff47bdb45aa in __sleep (seconds=0) at ../sysdeps/posix/sleep.c:55<br>#2 0x00007ff47cd59d75 in PetscSleep (s=<optimized out>) at /home/fghoussen/Documents/INRIA/petsc/src/sys/utils/psleep.c:50<br>#3 0x00007ff47cd15c11 in PetscAttachDebugger () at /home/fghoussen/Documents/INRIA/petsc/src/sys/error/adebug.c:388<br>#4 0x00007ff47cd16434 in PetscAttachDebuggerErrorHandler (comm=<optimized out>, line=<optimized out>, fun=<optimized out>, file=<optimized out>, num=<optimized out>, p=<optimized out>, <br> mess=0x7ffe1e7f6fe0 "Cannot get subcomm viewer for binary files or sockets unless SubViewer contains the rank 0 process", ctx=0x0) at /home/fghoussen/Documents/INRIA/petsc/src/sys/error/adebug.c:450<br>#5 0x00007ff47cd16a57 in PetscError (comm=0x556a39840420, line=line@entry=45, func=func@entry=0x7ff47d9581f0 <__func__.15647> "PetscViewerGetSubViewer_Binary", <br> file=file@entry=0x7ff47d9578f8 "/home/fghoussen/Documents/INRIA/petsc/src/sys/classes/viewer/impls/binary/binv.c", n=n@entry=56, p=p@entry=PETSC_ERROR_INITIAL, <br> mess=0x7ff47d957a08 "Cannot get subcomm viewer for binary files or sockets unless SubViewer contains the rank 0 process") at /home/fghoussen/Documents/INRIA/petsc/src/sys/error/err.c:367<br>#6 0x00007ff47cda148b in PetscViewerGetSubViewer_Binary (viewer=0x556a3984e260, comm=<optimized out>, outviewer=0x7ffe1e7f7958)<br> at /home/fghoussen/Documents/INRIA/petsc/src/sys/classes/viewer/impls/binary/binv.c:45<br>#7 0x00007ff47cdbbfb9 in PetscViewerGetSubViewer (viewer=viewer@entry=0x556a3984e260, comm=comm@entry=0x556a377e40e0 <ompi_mpi_comm_self>, outviewer=outviewer@entry=0x7ffe1e7f7958)<br> at /home/fghoussen/Documents/INRIA/petsc/src/sys/classes/viewer/interface/dupl.c:41<br>#8 0x00007ff47cefa6b4 in MatView_IS (A=<optimized out>, viewer=0x556a3984e260) at /home/fghoussen/Documents/INRIA/petsc/src/mat/impls/is/matis.c:1569<br>#9 0x00007ff47ceda6a3 in MatView (mat=0x556a3983f930, viewer=<optimized out>) at /home/fghoussen/Documents/INRIA/petsc/src/mat/interface/matrix.c:1015<br>#10 0x0000556a375e300a in main ()<br><br></div><div>The problem is only for binary export. When I comment it, I get no error :<br></div><div><br></div><div>>> mpirun -n 2 ./matExport.exe<br>mat type is mpiaij </div><div><br>>> mpirun -n 2 ./matExport.exe is<br>mat type is is <br>MatSetLocalToGlobalMapping done<br><br></div><div><br></div><div><br></div><hr id="zwchr"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;" data-mce-style="border-left: 2px solid #1010FF; margin-left: 5px; padding-left: 5px; color: #000; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>De: </b>"Stefano Zampini" <stefano.zampini@gmail.com><br><b>À: </b>"Franck Houssen" <franck.houssen@inria.fr><br><b>Cc: </b>"Pierre Jolivet" <Pierre.Jolivet@enseeiht.fr>, "petsc-dev" <petsc-dev@mcs.anl.gov><br><b>Envoyé: </b>Mercredi 13 Décembre 2017 18:29:13<br><b>Objet: </b>Re: [petsc-dev] MatIS export<br><div><br></div><div dir="auto">MatSetType + MatSetLocalToGlobalMapping<div dir="auto">is equivalent to MatCreateIS. Look at the code for MatCreateIS.</div></div><div class="gmail_extra"><br><div class="gmail_quote">Il 13 Dic 2017 7:32 PM, "Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank" data-mce-href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>> ha scritto:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex" data-mce-style="margin: 0 0 0 .8ex; border-left: 1px #ccc solid; padding-left: 1ex;"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt;color:#000000" data-mce-style="font-family: times new roman,new york,times,serif; font-size: 12pt; color: #000000;"><div>Thanks. Working now. I missed that. I believed "MatSetType + MatSetLocalToGlobalMapping" <=> "MatCreateIS(..., rmap, cmap, ...)" : I got that wrong.<br></div><div><br></div><div>Franck<br></div><div><br></div><hr id="m_-1129223978753723038zwchr"><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt" data-mce-style="border-left: 2px solid #1010ff; margin-left: 5px; padding-left: 5px; color: #000; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>De: </b>"Pierre Jolivet" <<a href="mailto:pierre.jolivet@enseeiht.fr" target="_blank" data-mce-href="mailto:pierre.jolivet@enseeiht.fr">pierre.jolivet@enseeiht.fr</a>><br><b>À: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank" data-mce-href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>><br><b>Cc: </b><a href="mailto:petsc-dev@mcs.anl.gov" target="_blank" data-mce-href="mailto:petsc-dev@mcs.anl.gov">petsc-dev@mcs.anl.gov</a><br><b>Envoyé: </b>Mardi 12 Décembre 2017 20:43:50<br><b>Objet: </b>Re: [petsc-dev] MatIS export<br><div><br></div>Hello Franck,<div>From the documentation: "You must call MatSetLocalToGlobalMapping() before using this matrix type.” (<a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MATIS.html" target="_blank" data-mce-href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MATIS.html">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MATIS.html</a>)</div><div>You are missing this call when your Mat is of type MATIS, thus the runtime error.</div><div><br></div><div>Thanks,</div><div>Pierre<br><div><br><blockquote><div>On 11 Dec 2017, at 5:42 PM, Franck Houssen <<a href="mailto:franck.houssen@inria.fr" target="_blank" data-mce-href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>> wrote:</div><br class="m_-1129223978753723038Apple-interchange-newline"><div><div><div style="font-family:"times new roman","new york",times,serif;font-size:12pt" data-mce-style="font-family: 'times new roman','new york',times,serif; font-size: 12pt;"><div>Seems there is a problem with the attachment. Here is the file :<br></div><div><br></div><div>>> more matExport.cpp <br>#include <petscmat.h><br>#include <petscsys.h><br><div><br></div>int main(int argc, char *argv[])<br>{<br> PetscInitialize(&argc, &argv, "", NULL);<br><div><br></div> Mat matrix;<br> MatCreate(PETSC_COMM_WORLD, &matrix);<br> const char* matType = (argc >= 2) ? argv[1] : MATMPIAIJ;<br> PetscPrintf(PETSC_COMM_WORLD, "mat type is %s \n", matType);<br> MatSetType(matrix, matType);<br> MatSetSizes(matrix, PETSC_DECIDE, PETSC_DECIDE, 10, 10);<br> MatSetUp(matrix);<br> for (int i = 0; i < 10; i++) MatSetValue(matrix, i, i, (double)(i+1.), ADD_VALUES);<br> MatAssemblyBegin(matrix, MAT_FINAL_ASSEMBLY);<br> MatAssemblyEnd(matrix, MAT_FINAL_ASSEMBLY);<br><div><br></div> PetscViewer viewer;<br> PetscViewerBinaryOpen(PETSC_COMM_WORLD, "matExport.bin", FILE_MODE_WRITE, &viewer);<br> MatView(matrix, viewer);<br> PetscViewerDestroy(&viewer);<br><div><br></div> PetscViewerASCIIOpen(PETSC_COMM_WORLD, "matExport.log", &viewer);<br> MatView(matrix, viewer);<br> PetscViewerDestroy(&viewer);<br><div><br></div> PetscViewerASCIIOpen(PETSC_COMM_WORLD, "matExport.mat", &viewer);<br> PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);<br> MatView(matrix, viewer);<br> PetscViewerDestroy(&viewer);<br><div><br></div> MatDestroy(&matrix);<br> PetscFinalize();<br>}<br><div><br></div><br></div><div><br></div><hr id="m_-1129223978753723038zwchr"><blockquote style="border-left-width:2px;border-left-style:solid;border-left-color:rgb(16,16,255);margin-left:5px;padding-left:5px;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt" data-mce-style="border-left-width: 2px; border-left-style: solid; border-left-color: #1010ff; margin-left: 5px; padding-left: 5px; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>De: </b>"Franck Houssen" <<a href="mailto:franck.houssen@inria.fr" target="_blank" data-mce-href="mailto:franck.houssen@inria.fr">franck.houssen@inria.fr</a>><br><b>À: </b><a href="mailto:petsc-dev@mcs.anl.gov" target="_blank" data-mce-href="mailto:petsc-dev@mcs.anl.gov">petsc-dev@mcs.anl.gov</a><br><b>Envoyé: </b>Lundi 11 Décembre 2017 17:39:40<br><b>Objet: </b>[petsc-dev] MatIS export<br><div><br></div><div style="font-family:"times new roman","new york",times,serif;font-size:12pt" data-mce-style="font-family: 'times new roman','new york',times,serif; font-size: 12pt;"><div>Reporting a small bug related to MatIS export (or is this not meant to be supported ?).<br></div><div><br></div><div>Franck<br></div><div><br></div><div>>> rm -f matExport.log matExport.mat matExport.bin; mpirun -n 2 ./matExport.exe <strong>is</strong>; more matExport.log matExport.mat matExport.bin<br>mat type is is <br>[0]PETSC ERROR: ------------------------------------------------------------------------<br>[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range<br>[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger<br>[0]PETSC ERROR: or see <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind" target="_blank" data-mce-href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a><br>[0]PETSC ERROR: or try <a href="http://valgrind.org" target="_blank" data-mce-href="http://valgrind.org">http://valgrind.org</a> on GNU/linux and Apple Mac OS X to find memory corruption errors<br>[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run <br>[0]PETSC ERROR: to get more information on the crash.<br>[1]PETSC ERROR: ------------------------------------------------------------------------<br>[1]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range<br>[1]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger<br>[1]PETSC ERROR: or see <a href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind" target="_blank" data-mce-href="http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind">http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind</a><br>[1]PETSC ERROR: or try <a href="http://valgrind.org" target="_blank" data-mce-href="http://valgrind.org">http://valgrind.org</a> on GNU/linux and Apple Mac OS X to find memory corruption errors<br>[1]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run <br>[1]PETSC ERROR: to get more information on the crash.<br>[0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------<br><div><br></div></div><div><br></div><div>>> rm -f matExport.log matExport.mat matExport.bin; mpirun -n 2 ./matExport.exe <strong>mpiaij</strong>; more matExport.log matExport.mat matExport.bin<br>mat type is mpiaij <br>::::::::::::::<br>matExport.log<br>::::::::::::::<br>Mat Object: 2 MPI processes<br> type: mpiaij<br>row 0: (0, 2.) <br>row 1: (1, 4.) <br>row 2: (2, 6.) <br>row 3: (3, 8.) <br>row 4: (4, 10.) <br>row 5: (5, 12.) <br>row 6: (6, 14.) <br>row 7: (7, 16.) <br>row 8: (8, 18.) <br>row 9: (9, 20.) <br>::::::::::::::<br>matExport.mat<br>::::::::::::::<br>%Mat Object: 2 MPI processes<br>% type: mpiaij<br>% Size = 10 10 <br>% Nonzeros = 10 <br>zzz = zeros(10,3);<br>zzz = [<br>1 1 2.0000000000000000e+00<br>2 2 4.0000000000000000e+00<br>3 3 6.0000000000000000e+00<br>4 4 8.0000000000000000e+00<br>5 5 1.0000000000000000e+01<br>6 6 1.2000000000000000e+01<br>7 7 1.4000000000000000e+01<br>8 8 1.6000000000000000e+01<br>9 9 1.8000000000000000e+01<br>10 10 2.0000000000000000e+01<br>];<br> Mat_0x557ffe276ba0_0 = spconvert(zzz);<br>::::::::::::::<br>matExport.bin<br>::::::::::::::<br><div><br></div><br><div><br></div><br><div><br></div></div><div><br></div><div><br></div></div></blockquote><div><br></div></div></div></div></blockquote></div><br></div></blockquote><div><br></div></div></div></blockquote></div></div></blockquote><div><br></div></div></body></html>