Hi Justin I have started a thread that was largely commented by Barry in March this year, maybe you can take a look at the archives (i.e. http://lists.mcs.anl.gov/pipermail/petsc-users/2015-March/024681.html and previous messages in the thread). Tha main conclusion is that if you have a matrix A, you should do something like this:
#define petsc_call(f) ierr=(f);CHKERRQ(ierr); petsc_call(PetscViewerDrawOpen(PETSC_COMM_WORLD, PETSC_NULL, title, PETSC_DECIDE, PETSC_DECIDE, size, size, &viewer)); petsc_call(PetscViewerDrawGetDraw(viewer, 0, &draw)); petsc_call(PetscDrawSetFromOptions(draw)); petsc_call(PetscDrawSetSaveFinalImage(draw, image)); petsc_call(MatView(A, viewer)); There are at least three drawbacks with this approach: 1. If you have a small matrix (say 1000x1000) and wanted to have a one-to-one bijection between a pixel and the elements of your matrix, setting the image size equal to the matrix size would not do the trick because the resulting image always includes a margin whose size depends on the size of the matrix in a way I could not figure out 2. You cannot have images bigger than the resolution of your X display 3. You have to compile PETSc with --with-afterimage-lib At the conference I asked Barry if there was another approach. He said that to overcome issue #2 you may define a virtual X display with a bigger resolution, but that seemed to complicate even more the issue. I then came up with a different approach, which is to dump a text file in the SNG (Scriptable Network Graphics) format. This is an idea developed by Eric Raymond in which a text file describes a bitmap using a base64 string (i.e. almost as ASCII art) which then is parsed and converted into a PNG with a utility named sng (http://sng.sourceforge.net/). I created a repository in https://bitbucket.org/gtheler/mat2sng/ where the main code loads a matrix from a binary file and calls a function mat2sng(). In its current implementation, it divides the matrix into blocks such that eack of these block corresponds to a single pixel in the output image and its colors depends on the sign of the sum of all the elements belonging to that block. If the block size is 1x1 then there is a correspondence between the output pixel and the matrix elements. It only works for SeqAIJ matrices because I copied the way the elements are read from MatView_SeqAIJ_ASCII() in src/mat/impls/aij/seq/aij.c. Given the base64 representation, one may use up to 32 shadows of red and blue to mark not just the sign of the blocks but also the relative values. If this idea actually works and is usable for some people, probably a new ASCII viewer of this type may be incorporated into next. Hope this helps. Greeting from Ginobilli's land. -- Germán Theler :: CTO Ingeniería & TICs CITES – Centro de Innovación Tecnológica Empresarial y Social S.A. Dirección General Sancor Seguros Grupo Sancor Seguros tel +54 3493 –428 500 – Int.: 3374 [email protected] www.cites-gss.com - www.gruposancorseguros.com On Wed, 2015-07-22 at 02:13 -0500, Justin Chang wrote: > Hi everyone, > > How do I print out the non-zero structure of a Matrix? Preferably to > an image file (e.g., png, eps, etc). > > Thanks, > Justin ________________________________ Imprima este mensaje sólo si es absolutamente necesario. Para imprimir, en lo posible utilice el papel de ambos lados. El Grupo Sancor Seguros se compromete con el cuidado del medioambiente. ************AVISO DE CONFIDENCIALIDAD************ El Grupo Sancor Seguros comunica que: Este mensaje y todos los archivos adjuntos a el son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por ley. Si usted recibió este mensaje erróneamente, por favor notifíquenos respondiendo al remitente, borre el mensaje original y destruya las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo. Todas las opiniones contenidas en este mail son propias del autor del mensaje. La publicación, uso, copia o impresión total o parcial de este mensaje o documentos adjuntos queda prohibida. Disposición DNDP 10-2008. El titular de los datos personales tiene la facultad de ejercer el derecho de acceso a los mismos en forma gratuita a intervalos no inferiores a seis meses, salvo que acredite un interés legítimo al efecto conforme lo establecido en el artículo 14, inciso 3 de la Ley 25.326. La DIRECCIÓN NACIONAL DE PROTECCIÓN DE DATOS PERSONALES, Organo de Control de la Ley 25.326, tiene la atribución de atender las denuncias y reclamos que se interpongan con relación al incumplimiento de las normas sobre la protección de datos personales.
