00001 #include <stdlib.h>
00002 #include <petscoptions.h>
00003 #include <petsc.h>
00004 #include "nmd.h"
00005 #include "anamod.h"
00006 #include "anamodsalsamodules.h"
00007 #if defined(HAVE_MYSQL)
00008 #include "mysql.h"
00009 MYSQL *dbase;
00010 #endif
00011
00012 #undef __FUNCT__
00013 #define __FUNCT__ "get_matrix"
00014 static PetscErrorCode get_matrix(Mat *A,PetscTruth *success)
00015 {
00016 MPI_Comm comm = MPI_COMM_WORLD; char option[1000];
00017 PetscTruth has; PetscViewer binary_dump; PetscErrorCode ierr;
00018
00019 PetscFunctionBegin;
00020 *success = PETSC_FALSE;
00021
00022 ierr = PetscOptionsGetString
00023 (PETSC_NULL,"-petsc",option,1000,&has); CHKERRQ(ierr);
00024 if (has) {
00025 PetscPrintf(comm,"reading matrix from petsc dump <%s>\n",option);
00026 ierr = PetscViewerBinaryOpen
00027 (comm,option,FILE_MODE_READ,&binary_dump); CHKERRQ(ierr);
00028 ierr = MatLoad(binary_dump,MATSEQAIJ,A); CHKERRQ(ierr);
00029 ierr = PetscViewerDestroy(binary_dump); CHKERRQ(ierr);
00030 *success = PETSC_TRUE; goto exit;
00031 }
00032
00033 ierr = PetscOptionsGetString
00034 (PETSC_NULL,"-matrixmarket",option,1000,&has); CHKERRQ(ierr);
00035 if (has) {
00036 PetscPrintf(comm,"matrix market read not yet supported\n");
00037 *success = PETSC_FALSE; goto exit;
00038 }
00039
00040 exit:
00041 CHKMEMQ;
00042 PetscFunctionReturn(0);
00043 }
00044
00045 #undef __FUNCT__
00046 #define __FUNCT__ "analyze_matrix"
00047 PetscErrorCode analyze_matrix(Mat A,NMD_metadata nmd)
00048 {
00049 char **categories,**modules;
00050 AnalysisDataType *types; int icat,imod,ncat,nmod;
00051 PetscErrorCode ierr;
00052
00053 PetscFunctionBegin;
00054 ierr = GetCategories(&categories,&ncat); CHKERRQ(ierr);
00055 for (icat=0; icat<ncat; icat++) {
00056 ierr = CategoryGetModules
00057 (categories[icat],&modules,&types,PETSC_NULL,&nmod); CHKERRQ(ierr);
00058 for (imod=0; imod<nmod; imod++) {
00059 AnalysisItem res; int reslen; PetscTruth success;
00060 ierr = ComputeQuantity
00061 ((AnaModNumericalProblem)A,categories[icat],modules[imod],
00062 &res,&reslen,&success); CHKERRQ(ierr);
00063 #if defined(HAVE_MYSQL)
00064
00065 #endif
00066 if (success) {
00067 AnalysisDataType type;
00068 ierr = GetDataType
00069 (categories[icat],modules[imod],&type); CHKERRQ(ierr);
00070 ierr = NMDSetArrayValue
00071 (nmd,categories[icat],modules[imod],
00072 (NMDDataType)type,(void*)&res,reslen); CHKERRQ(ierr);
00073 }
00074 }
00075 }
00076 PetscFunctionReturn(0);
00077 }
00078
00079
00080 #undef __FUNCT__
00081 #define __FUNCT__ "main"
00082 int main(int argc,char **argv)
00083 {
00084 Mat A; NMD_metadata nmd; PetscTruth table,success;
00085 PetscErrorCode ierr;
00086
00087 PetscFunctionBegin;
00088 PetscInitialize(&argc,&argv,0,0);
00089 ierr = AnaModInitialize(); CHKERRQ(ierr);
00090 ierr = AnaModRegisterSalsaModules(); CHKERRQ(ierr);
00091
00092 ierr = PetscOptionsHasName(PETSC_NULL,"-table",&table); CHKERRQ(ierr);
00093 if (table) {
00094 #if defined(HAVE_MYSQL)
00095 printf("CREATE TABLE anamod_data (\n");
00096 {
00097 int ncat,icat,iwrite=0; char **cats;
00098 ierr = GetCategories(&cats,&ncat); CHKERRQ(ierr);
00099 for (icat=0; icat<ncat; icat++) {
00100 int ncmp,icmp; char **cmps; AnalysisDataType *types;
00101 ierr = CategoryGetModules
00102 (cats[icat],&cmps,&types,NULL,&ncmp); CHKERRQ(ierr);
00103 for (icmp=0; icmp<ncmp; icmp++) {
00104 char *type;
00105 if (iwrite>0) printf(",\n"); iwrite++;
00106 ierr = AnaModGetTypeMySQLName(types[icmp],&type); CHKERRQ(ierr);
00107 printf(" `%s-%s` %s",cats[icat],cmps[icmp],type);
00108
00109 }
00110 }
00111 }
00112
00113
00114
00115 #else
00116 SETERRQ(1,"Anamod was compiled without MySQL support");
00117 #endif
00118 printf("\n)\n");
00119 goto finalize;
00120 }
00121 ierr = get_matrix(&A,&success); CHKERRQ(ierr);
00122 if (!success) goto exit;
00123
00124 ierr = NMDCreateObject(&nmd); CHKERRQ(ierr);
00125 ierr = analyze_matrix(A,nmd); CHKERRQ(ierr);
00126 ierr = NMDViewObject(nmd); CHKERRQ(ierr);
00127 {
00128 char *key,*val;
00129 ierr = NMDReportObject(nmd,NMDFalse,&key,&val,'\t',0,0); CHKERRQ(ierr);
00130 printf("Keys: %s\nValues: %s\n",key,val);
00131
00132 }
00133 ierr = NMDDestroyObject(nmd); CHKERRQ(ierr);
00134
00135 exit:
00136 #if defined(HAVE_MYSQL)
00137 mysql_close(dbase);
00138 finalize:
00139 #endif
00140 ierr = AnaModDeregisterSalsaModules(); CHKERRQ(ierr);
00141 ierr = AnaModFinalize(); CHKERRQ(ierr);
00142 PetscFinalize();
00143 PetscFunctionReturn(0);
00144 }