printmatinfo.c

Go to the documentation of this file.
00001 /*
00002     This file is part of magpar.
00003 
00004     Copyright (C) 2006-2010 Werner Scholz
00005 
00006     www:   http://www.magpar.net/
00007     email: magpar(at)magpar.net
00008 
00009     magpar is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     magpar is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with magpar; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 /* $Id: printmatinfo.c 2962 2010-02-04 19:50:44Z scholz $ */
00025 
00026 #include "util.h"
00027 
00028 int PrintMatInfo(Mat A,MatInfoType flag)
00029 {
00030   int ierr;
00031   int rank,size;
00032   ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
00033   ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
00034 
00035   PetscTruth oinfo;
00036   PetscOptionsHasName(PETSC_NULL,"-info",&oinfo);
00037 if (oinfo) {
00038 
00039   MatInfo info;
00040   ierr = MatGetInfo(A,MAT_GLOBAL_SUM,&info);CHKERRQ(ierr);
00041 
00042   PetscErrorCode (*printffunc)(MPI_Comm comm,const char format[],...);
00043 
00044   if (flag==MAT_LOCAL) {
00045     printffunc=PetscSynchronizedPrintf;
00046   }
00047   else {
00048     printffunc=PetscPrintf;
00049   }
00050 
00051 #if PETSC_VERSION >= 300
00052   PetscInt grows,gcols;
00053   ierr = MatGetSize(A,&grows,&gcols);CHKERRQ(ierr);
00054   printffunc(PETSC_COMM_WORLD,"  <%i> global rows and columns: %g x %g\n",
00055     rank,grows,gcols);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00056 
00057   PetscInt lrows,lcols;
00058   ierr = MatGetLocalSize(A,&lrows,&lcols);CHKERRQ(ierr);
00059   printffunc(PETSC_COMM_WORLD,"  <%i> local rows and columns: %g x %g (%g %%)\n",
00060     rank,lrows,lcols,100.0*lrows/grows);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00061 
00062   PetscInt bs;
00063   ierr = MatGetBlockSize(A,&bs);CHKERRQ(ierr);
00064   printffunc(PETSC_COMM_WORLD,"  <%i> block size %g\n",
00065     rank,bs);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00066 #else
00067   printffunc(PETSC_COMM_WORLD,"  <%i> global rows and columns: %g x %g\n",
00068     rank,info.rows_global,info.columns_global);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00069   printffunc(PETSC_COMM_WORLD,"  <%i> local rows and columns: %g x %g (%g %%)\n",
00070     rank,info.rows_local,info.columns_local,100.0*info.rows_local/info.rows_global);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00071   printffunc(PETSC_COMM_WORLD,"  <%i> block size %g\n",
00072     rank,info.block_size);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00073 #endif
00074   printffunc(PETSC_COMM_WORLD,"  <%i> nonzeroes allocated: %g (%g %%)  used: %g (%g %%)  unneeded: %g (%g %%)\n",
00075     rank,info.nz_allocated,100.0*info.nz_allocated/info.nz_used,info.nz_used,100.0*info.nz_used/info.nz_used,info.nz_unneeded,100.0*info.nz_unneeded/info.nz_used);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00076   printffunc(PETSC_COMM_WORLD,"  <%i> memory allocated: %g\n",
00077     rank,info.memory);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00078   printffunc(PETSC_COMM_WORLD,"  <%i> number of matrix assemblies called: %g\n",
00079     rank,info.assemblies);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00080   printffunc(PETSC_COMM_WORLD,"  <%i> number of mallocs during MatSetValues: %g\n",
00081     rank,info.mallocs);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00082   printffunc(PETSC_COMM_WORLD,"  <%i> fill_ratio_given: %g  fill_ratio_needed: %g  for LU/ILU\n",
00083     rank,info.fill_ratio_given,info.fill_ratio_needed);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00084   printffunc(PETSC_COMM_WORLD,"  <%i> number of mallocs during factorization: %g\n",
00085     rank,info.factor_mallocs);if (flag==MAT_LOCAL) PetscSynchronizedFlush(PETSC_COMM_WORLD);
00086 
00087 }
00088 
00089   return(0);
00090 }
00091 
00092 int PrintMatInfoAll(Mat A)
00093 {
00094   int ierr;
00095 
00096   int rank,size;
00097   ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr);
00098   ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);
00099 
00100   PetscTruth info;
00101   PetscOptionsHasName(PETSC_NULL,"-info",&info);
00102 if (info) {
00103 
00104   if (size>1) {
00105     PetscPrintf(PETSC_COMM_WORLD,"local matrix info:\n");
00106     ierr = PrintMatInfo(A,MAT_LOCAL);CHKERRQ(ierr);
00107     PetscPrintf(PETSC_COMM_WORLD,"global max. matrix info:\n");
00108     ierr = PrintMatInfo(A,MAT_GLOBAL_MAX);CHKERRQ(ierr);
00109   }
00110   PetscPrintf(PETSC_COMM_WORLD,"global sum matrix info:\n");
00111   ierr = PrintMatInfo(A,MAT_GLOBAL_SUM);CHKERRQ(ierr);
00112 
00113 }
00114 
00115   return(0);
00116 }

magpar - Parallel Finite Element Micromagnetics Package
Copyright (C) 2002-2010 Werner Scholz