1*47c6ae99SBarry Smith #define PETSCDM_DLL 2*47c6ae99SBarry Smith 3*47c6ae99SBarry Smith /* 4*47c6ae99SBarry Smith Plots vectors obtained with DACreate2d() 5*47c6ae99SBarry Smith */ 6*47c6ae99SBarry Smith 7*47c6ae99SBarry Smith #include "private/daimpl.h" /*I "petscda.h" I*/ 8*47c6ae99SBarry Smith #include "private/vecimpl.h" 9*47c6ae99SBarry Smith 10*47c6ae99SBarry Smith /* 11*47c6ae99SBarry Smith The data that is passed into the graphics callback 12*47c6ae99SBarry Smith */ 13*47c6ae99SBarry Smith typedef struct { 14*47c6ae99SBarry Smith PetscInt m,n,step,k; 15*47c6ae99SBarry Smith PetscReal min,max,scale; 16*47c6ae99SBarry Smith PetscScalar *xy,*v; 17*47c6ae99SBarry Smith PetscBool showgrid; 18*47c6ae99SBarry Smith } ZoomCtx; 19*47c6ae99SBarry Smith 20*47c6ae99SBarry Smith /* 21*47c6ae99SBarry Smith This does the drawing for one particular field 22*47c6ae99SBarry Smith in one particular set of coordinates. It is a callback 23*47c6ae99SBarry Smith called from PetscDrawZoom() 24*47c6ae99SBarry Smith */ 25*47c6ae99SBarry Smith #undef __FUNCT__ 26*47c6ae99SBarry Smith #define __FUNCT__ "VecView_MPI_Draw_DA2d_Zoom" 27*47c6ae99SBarry Smith PetscErrorCode VecView_MPI_Draw_DA2d_Zoom(PetscDraw draw,void *ctx) 28*47c6ae99SBarry Smith { 29*47c6ae99SBarry Smith ZoomCtx *zctx = (ZoomCtx*)ctx; 30*47c6ae99SBarry Smith PetscErrorCode ierr; 31*47c6ae99SBarry Smith PetscInt m,n,i,j,k,step,id,c1,c2,c3,c4; 32*47c6ae99SBarry Smith PetscReal s,min,x1,x2,x3,x4,y_1,y2,y3,y4; 33*47c6ae99SBarry Smith PetscScalar *v,*xy; 34*47c6ae99SBarry Smith 35*47c6ae99SBarry Smith PetscFunctionBegin; 36*47c6ae99SBarry Smith m = zctx->m; 37*47c6ae99SBarry Smith n = zctx->n; 38*47c6ae99SBarry Smith step = zctx->step; 39*47c6ae99SBarry Smith k = zctx->k; 40*47c6ae99SBarry Smith v = zctx->v; 41*47c6ae99SBarry Smith xy = zctx->xy; 42*47c6ae99SBarry Smith s = zctx->scale; 43*47c6ae99SBarry Smith min = zctx->min; 44*47c6ae99SBarry Smith 45*47c6ae99SBarry Smith /* PetscDraw the contour plot patch */ 46*47c6ae99SBarry Smith for (j=0; j<n-1; j++) { 47*47c6ae99SBarry Smith for (i=0; i<m-1; i++) { 48*47c6ae99SBarry Smith #if !defined(PETSC_USE_COMPLEX) 49*47c6ae99SBarry Smith id = i+j*m; x1 = xy[2*id];y_1 = xy[2*id+1];c1 = (int)(PETSC_DRAW_BASIC_COLORS+s*(v[k+step*id]-min)); 50*47c6ae99SBarry Smith id = i+j*m+1; x2 = xy[2*id];y2 = y_1; c2 = (int)(PETSC_DRAW_BASIC_COLORS+s*(v[k+step*id]-min)); 51*47c6ae99SBarry Smith id = i+j*m+1+m;x3 = x2; y3 = xy[2*id+1];c3 = (int)(PETSC_DRAW_BASIC_COLORS+s*(v[k+step*id]-min)); 52*47c6ae99SBarry Smith id = i+j*m+m; x4 = x1; y4 = y3; c4 = (int)(PETSC_DRAW_BASIC_COLORS+s*(v[k+step*id]-min)); 53*47c6ae99SBarry Smith #else 54*47c6ae99SBarry Smith id = i+j*m; x1 = PetscRealPart(xy[2*id]);y_1 = PetscRealPart(xy[2*id+1]);c1 = (int)(PETSC_DRAW_BASIC_COLORS+s*(PetscRealPart(v[k+step*id])-min)); 55*47c6ae99SBarry Smith id = i+j*m+1; x2 = PetscRealPart(xy[2*id]);y2 = y_1; c2 = (int)(PETSC_DRAW_BASIC_COLORS+s*(PetscRealPart(v[k+step*id])-min)); 56*47c6ae99SBarry Smith id = i+j*m+1+m;x3 = x2; y3 = PetscRealPart(xy[2*id+1]);c3 = (int)(PETSC_DRAW_BASIC_COLORS+s*(PetscRealPart(v[k+step*id])-min)); 57*47c6ae99SBarry Smith id = i+j*m+m; x4 = x1; y4 = y3; c4 = (int)(PETSC_DRAW_BASIC_COLORS+s*(PetscRealPart(v[k+step*id])-min)); 58*47c6ae99SBarry Smith #endif 59*47c6ae99SBarry Smith ierr = PetscDrawTriangle(draw,x1,y_1,x2,y2,x3,y3,c1,c2,c3);CHKERRQ(ierr); 60*47c6ae99SBarry Smith ierr = PetscDrawTriangle(draw,x1,y_1,x3,y3,x4,y4,c1,c3,c4);CHKERRQ(ierr); 61*47c6ae99SBarry Smith if (zctx->showgrid) { 62*47c6ae99SBarry Smith ierr = PetscDrawLine(draw,x1,y_1,x2,y2,PETSC_DRAW_BLACK);CHKERRQ(ierr); 63*47c6ae99SBarry Smith ierr = PetscDrawLine(draw,x2,y2,x3,y3,PETSC_DRAW_BLACK);CHKERRQ(ierr); 64*47c6ae99SBarry Smith ierr = PetscDrawLine(draw,x3,y3,x4,y4,PETSC_DRAW_BLACK);CHKERRQ(ierr); 65*47c6ae99SBarry Smith ierr = PetscDrawLine(draw,x4,y4,x1,y_1,PETSC_DRAW_BLACK);CHKERRQ(ierr); 66*47c6ae99SBarry Smith } 67*47c6ae99SBarry Smith } 68*47c6ae99SBarry Smith } 69*47c6ae99SBarry Smith PetscFunctionReturn(0); 70*47c6ae99SBarry Smith } 71*47c6ae99SBarry Smith 72*47c6ae99SBarry Smith #undef __FUNCT__ 73*47c6ae99SBarry Smith #define __FUNCT__ "VecView_MPI_Draw_DA2d" 74*47c6ae99SBarry Smith PetscErrorCode VecView_MPI_Draw_DA2d(Vec xin,PetscViewer viewer) 75*47c6ae99SBarry Smith { 76*47c6ae99SBarry Smith DA da,dac,dag; 77*47c6ae99SBarry Smith PetscErrorCode ierr; 78*47c6ae99SBarry Smith PetscMPIInt rank; 79*47c6ae99SBarry Smith PetscInt igstart,N,s,M,istart,isize,jgstart,w; 80*47c6ae99SBarry Smith const PetscInt *lx,*ly; 81*47c6ae99SBarry Smith PetscReal coors[4],ymin,ymax,xmin,xmax; 82*47c6ae99SBarry Smith PetscDraw draw,popup; 83*47c6ae99SBarry Smith PetscBool isnull,useports = PETSC_FALSE; 84*47c6ae99SBarry Smith MPI_Comm comm; 85*47c6ae99SBarry Smith Vec xlocal,xcoor,xcoorl; 86*47c6ae99SBarry Smith DAPeriodicType periodic; 87*47c6ae99SBarry Smith DAStencilType st; 88*47c6ae99SBarry Smith ZoomCtx zctx; 89*47c6ae99SBarry Smith PetscDrawViewPorts *ports; 90*47c6ae99SBarry Smith PetscViewerFormat format; 91*47c6ae99SBarry Smith 92*47c6ae99SBarry Smith PetscFunctionBegin; 93*47c6ae99SBarry Smith zctx.showgrid = PETSC_FALSE; 94*47c6ae99SBarry Smith ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr); 95*47c6ae99SBarry Smith ierr = PetscDrawIsNull(draw,&isnull);CHKERRQ(ierr); if (isnull) PetscFunctionReturn(0); 96*47c6ae99SBarry Smith 97*47c6ae99SBarry Smith ierr = PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);CHKERRQ(ierr); 98*47c6ae99SBarry Smith if (!da) SETERRQ(((PetscObject)xin)->comm,PETSC_ERR_ARG_WRONG,"Vector not generated from a DA"); 99*47c6ae99SBarry Smith 100*47c6ae99SBarry Smith ierr = PetscObjectGetComm((PetscObject)xin,&comm);CHKERRQ(ierr); 101*47c6ae99SBarry Smith ierr = MPI_Comm_rank(comm,&rank);CHKERRQ(ierr); 102*47c6ae99SBarry Smith 103*47c6ae99SBarry Smith ierr = DAGetInfo(da,0,&M,&N,0,&zctx.m,&zctx.n,0,&w,&s,&periodic,&st);CHKERRQ(ierr); 104*47c6ae99SBarry Smith ierr = DAGetOwnershipRanges(da,&lx,&ly,PETSC_NULL);CHKERRQ(ierr); 105*47c6ae99SBarry Smith 106*47c6ae99SBarry Smith /* 107*47c6ae99SBarry Smith Obtain a sequential vector that is going to contain the local values plus ONE layer of 108*47c6ae99SBarry Smith ghosted values to draw the graphics from. We also need its corresponding DA (dac) that will 109*47c6ae99SBarry Smith update the local values pluse ONE layer of ghost values. 110*47c6ae99SBarry Smith */ 111*47c6ae99SBarry Smith ierr = PetscObjectQuery((PetscObject)da,"GraphicsGhosted",(PetscObject*)&xlocal);CHKERRQ(ierr); 112*47c6ae99SBarry Smith if (!xlocal) { 113*47c6ae99SBarry Smith if (periodic != DA_NONPERIODIC || s != 1 || st != DA_STENCIL_BOX) { 114*47c6ae99SBarry Smith /* 115*47c6ae99SBarry Smith if original da is not of stencil width one, or periodic or not a box stencil then 116*47c6ae99SBarry Smith create a special DA to handle one level of ghost points for graphics 117*47c6ae99SBarry Smith */ 118*47c6ae99SBarry Smith ierr = DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,M,N,zctx.m,zctx.n,w,1,lx,ly,&dac);CHKERRQ(ierr); 119*47c6ae99SBarry Smith ierr = PetscInfo(da,"Creating auxilary DA for managing graphics ghost points\n");CHKERRQ(ierr); 120*47c6ae99SBarry Smith } else { 121*47c6ae99SBarry Smith /* otherwise we can use the da we already have */ 122*47c6ae99SBarry Smith dac = da; 123*47c6ae99SBarry Smith } 124*47c6ae99SBarry Smith /* create local vector for holding ghosted values used in graphics */ 125*47c6ae99SBarry Smith ierr = DACreateLocalVector(dac,&xlocal);CHKERRQ(ierr); 126*47c6ae99SBarry Smith if (dac != da) { 127*47c6ae99SBarry Smith /* don't keep any public reference of this DA, is is only available through xlocal */ 128*47c6ae99SBarry Smith ierr = DADestroy(dac);CHKERRQ(ierr); 129*47c6ae99SBarry Smith } else { 130*47c6ae99SBarry Smith /* remove association between xlocal and da, because below we compose in the opposite 131*47c6ae99SBarry Smith direction and if we left this connect we'd get a loop, so the objects could 132*47c6ae99SBarry Smith never be destroyed */ 133*47c6ae99SBarry Smith ierr = PetscObjectCompose((PetscObject)xlocal,"DA",0);CHKERRQ(ierr); 134*47c6ae99SBarry Smith } 135*47c6ae99SBarry Smith ierr = PetscObjectCompose((PetscObject)da,"GraphicsGhosted",(PetscObject)xlocal);CHKERRQ(ierr); 136*47c6ae99SBarry Smith ierr = PetscObjectDereference((PetscObject)xlocal);CHKERRQ(ierr); 137*47c6ae99SBarry Smith } else { 138*47c6ae99SBarry Smith if (periodic == DA_NONPERIODIC && s == 1 && st == DA_STENCIL_BOX) { 139*47c6ae99SBarry Smith dac = da; 140*47c6ae99SBarry Smith } else { 141*47c6ae99SBarry Smith ierr = PetscObjectQuery((PetscObject)xlocal,"DA",(PetscObject*)&dac);CHKERRQ(ierr); 142*47c6ae99SBarry Smith } 143*47c6ae99SBarry Smith } 144*47c6ae99SBarry Smith 145*47c6ae99SBarry Smith /* 146*47c6ae99SBarry Smith Get local (ghosted) values of vector 147*47c6ae99SBarry Smith */ 148*47c6ae99SBarry Smith ierr = DAGlobalToLocalBegin(dac,xin,INSERT_VALUES,xlocal);CHKERRQ(ierr); 149*47c6ae99SBarry Smith ierr = DAGlobalToLocalEnd(dac,xin,INSERT_VALUES,xlocal);CHKERRQ(ierr); 150*47c6ae99SBarry Smith ierr = VecGetArray(xlocal,&zctx.v);CHKERRQ(ierr); 151*47c6ae99SBarry Smith 152*47c6ae99SBarry Smith /* get coordinates of nodes */ 153*47c6ae99SBarry Smith ierr = DAGetCoordinates(da,&xcoor);CHKERRQ(ierr); 154*47c6ae99SBarry Smith if (!xcoor) { 155*47c6ae99SBarry Smith ierr = DASetUniformCoordinates(da,0.0,1.0,0.0,1.0,0.0,0.0);CHKERRQ(ierr); 156*47c6ae99SBarry Smith ierr = DAGetCoordinates(da,&xcoor);CHKERRQ(ierr); 157*47c6ae99SBarry Smith } 158*47c6ae99SBarry Smith 159*47c6ae99SBarry Smith /* 160*47c6ae99SBarry Smith Determine the min and max coordinates in plot 161*47c6ae99SBarry Smith */ 162*47c6ae99SBarry Smith ierr = VecStrideMin(xcoor,0,PETSC_NULL,&xmin);CHKERRQ(ierr); 163*47c6ae99SBarry Smith ierr = VecStrideMax(xcoor,0,PETSC_NULL,&xmax);CHKERRQ(ierr); 164*47c6ae99SBarry Smith ierr = VecStrideMin(xcoor,1,PETSC_NULL,&ymin);CHKERRQ(ierr); 165*47c6ae99SBarry Smith ierr = VecStrideMax(xcoor,1,PETSC_NULL,&ymax);CHKERRQ(ierr); 166*47c6ae99SBarry Smith coors[0] = xmin - .05*(xmax- xmin); coors[2] = xmax + .05*(xmax - xmin); 167*47c6ae99SBarry Smith coors[1] = ymin - .05*(ymax- ymin); coors[3] = ymax + .05*(ymax - ymin); 168*47c6ae99SBarry Smith ierr = PetscInfo4(da,"Preparing DA 2d contour plot coordinates %G %G %G %G\n",coors[0],coors[1],coors[2],coors[3]);CHKERRQ(ierr); 169*47c6ae99SBarry Smith 170*47c6ae99SBarry Smith /* 171*47c6ae99SBarry Smith get local ghosted version of coordinates 172*47c6ae99SBarry Smith */ 173*47c6ae99SBarry Smith ierr = PetscObjectQuery((PetscObject)da,"GraphicsCoordinateGhosted",(PetscObject*)&xcoorl);CHKERRQ(ierr); 174*47c6ae99SBarry Smith if (!xcoorl) { 175*47c6ae99SBarry Smith /* create DA to get local version of graphics */ 176*47c6ae99SBarry Smith ierr = DACreate2d(comm,DA_NONPERIODIC,DA_STENCIL_BOX,M,N,zctx.m,zctx.n,2,1,lx,ly,&dag);CHKERRQ(ierr); 177*47c6ae99SBarry Smith ierr = PetscInfo(dag,"Creating auxilary DA for managing graphics coordinates ghost points\n");CHKERRQ(ierr); 178*47c6ae99SBarry Smith ierr = DACreateLocalVector(dag,&xcoorl);CHKERRQ(ierr); 179*47c6ae99SBarry Smith ierr = PetscObjectCompose((PetscObject)da,"GraphicsCoordinateGhosted",(PetscObject)xcoorl);CHKERRQ(ierr); 180*47c6ae99SBarry Smith ierr = DADestroy(dag);CHKERRQ(ierr);/* dereference dag */ 181*47c6ae99SBarry Smith ierr = PetscObjectDereference((PetscObject)xcoorl);CHKERRQ(ierr); 182*47c6ae99SBarry Smith } else { 183*47c6ae99SBarry Smith ierr = PetscObjectQuery((PetscObject)xcoorl,"DA",(PetscObject*)&dag);CHKERRQ(ierr); 184*47c6ae99SBarry Smith } 185*47c6ae99SBarry Smith ierr = DAGlobalToLocalBegin(dag,xcoor,INSERT_VALUES,xcoorl);CHKERRQ(ierr); 186*47c6ae99SBarry Smith ierr = DAGlobalToLocalEnd(dag,xcoor,INSERT_VALUES,xcoorl);CHKERRQ(ierr); 187*47c6ae99SBarry Smith ierr = VecGetArray(xcoorl,&zctx.xy);CHKERRQ(ierr); 188*47c6ae99SBarry Smith 189*47c6ae99SBarry Smith /* 190*47c6ae99SBarry Smith Get information about size of area each processor must do graphics for 191*47c6ae99SBarry Smith */ 192*47c6ae99SBarry Smith ierr = DAGetInfo(dac,0,&M,&N,0,0,0,0,&zctx.step,0,&periodic,0);CHKERRQ(ierr); 193*47c6ae99SBarry Smith ierr = DAGetGhostCorners(dac,&igstart,&jgstart,0,&zctx.m,&zctx.n,0);CHKERRQ(ierr); 194*47c6ae99SBarry Smith ierr = DAGetCorners(dac,&istart,0,0,&isize,0,0);CHKERRQ(ierr); 195*47c6ae99SBarry Smith 196*47c6ae99SBarry Smith ierr = PetscOptionsGetTruth(PETSC_NULL,"-draw_contour_grid",&zctx.showgrid,PETSC_NULL);CHKERRQ(ierr); 197*47c6ae99SBarry Smith 198*47c6ae99SBarry Smith ierr = PetscViewerGetFormat(viewer,&format);CHKERRQ(ierr); 199*47c6ae99SBarry Smith ierr = PetscOptionsGetTruth(PETSC_NULL,"-draw_ports",&useports,PETSC_NULL);CHKERRQ(ierr); 200*47c6ae99SBarry Smith if (useports || format == PETSC_VIEWER_DRAW_PORTS){ 201*47c6ae99SBarry Smith ierr = PetscDrawSynchronizedClear(draw);CHKERRQ(ierr); 202*47c6ae99SBarry Smith ierr = PetscDrawViewPortsCreate(draw,zctx.step,&ports);CHKERRQ(ierr); 203*47c6ae99SBarry Smith } 204*47c6ae99SBarry Smith /* 205*47c6ae99SBarry Smith Loop over each field; drawing each in a different window 206*47c6ae99SBarry Smith */ 207*47c6ae99SBarry Smith for (zctx.k=0; zctx.k<zctx.step; zctx.k++) { 208*47c6ae99SBarry Smith if (useports) { 209*47c6ae99SBarry Smith ierr = PetscDrawViewPortsSet(ports,zctx.k);CHKERRQ(ierr); 210*47c6ae99SBarry Smith } else { 211*47c6ae99SBarry Smith ierr = PetscViewerDrawGetDraw(viewer,zctx.k,&draw);CHKERRQ(ierr); 212*47c6ae99SBarry Smith ierr = PetscDrawSynchronizedClear(draw);CHKERRQ(ierr); 213*47c6ae99SBarry Smith } 214*47c6ae99SBarry Smith 215*47c6ae99SBarry Smith /* 216*47c6ae99SBarry Smith Determine the min and max color in plot 217*47c6ae99SBarry Smith */ 218*47c6ae99SBarry Smith ierr = VecStrideMin(xin,zctx.k,PETSC_NULL,&zctx.min);CHKERRQ(ierr); 219*47c6ae99SBarry Smith ierr = VecStrideMax(xin,zctx.k,PETSC_NULL,&zctx.max);CHKERRQ(ierr); 220*47c6ae99SBarry Smith if (zctx.min == zctx.max) { 221*47c6ae99SBarry Smith zctx.min -= 1.e-12; 222*47c6ae99SBarry Smith zctx.max += 1.e-12; 223*47c6ae99SBarry Smith } 224*47c6ae99SBarry Smith 225*47c6ae99SBarry Smith if (!rank) { 226*47c6ae99SBarry Smith const char *title; 227*47c6ae99SBarry Smith 228*47c6ae99SBarry Smith ierr = DAGetFieldName(da,zctx.k,&title);CHKERRQ(ierr); 229*47c6ae99SBarry Smith if (title) { 230*47c6ae99SBarry Smith ierr = PetscDrawSetTitle(draw,title);CHKERRQ(ierr); 231*47c6ae99SBarry Smith } 232*47c6ae99SBarry Smith } 233*47c6ae99SBarry Smith ierr = PetscDrawSetCoordinates(draw,coors[0],coors[1],coors[2],coors[3]);CHKERRQ(ierr); 234*47c6ae99SBarry Smith ierr = PetscInfo2(da,"DA 2d contour plot min %G max %G\n",zctx.min,zctx.max);CHKERRQ(ierr); 235*47c6ae99SBarry Smith 236*47c6ae99SBarry Smith ierr = PetscDrawGetPopup(draw,&popup);CHKERRQ(ierr); 237*47c6ae99SBarry Smith if (popup) {ierr = PetscDrawScalePopup(popup,zctx.min,zctx.max);CHKERRQ(ierr);} 238*47c6ae99SBarry Smith 239*47c6ae99SBarry Smith zctx.scale = (245.0 - PETSC_DRAW_BASIC_COLORS)/(zctx.max - zctx.min); 240*47c6ae99SBarry Smith 241*47c6ae99SBarry Smith ierr = PetscDrawZoom(draw,VecView_MPI_Draw_DA2d_Zoom,&zctx);CHKERRQ(ierr); 242*47c6ae99SBarry Smith } 243*47c6ae99SBarry Smith if (useports){ 244*47c6ae99SBarry Smith ierr = PetscDrawViewPortsDestroy(ports);CHKERRQ(ierr); 245*47c6ae99SBarry Smith } 246*47c6ae99SBarry Smith 247*47c6ae99SBarry Smith ierr = VecRestoreArray(xcoorl,&zctx.xy);CHKERRQ(ierr); 248*47c6ae99SBarry Smith ierr = VecRestoreArray(xlocal,&zctx.v);CHKERRQ(ierr); 249*47c6ae99SBarry Smith PetscFunctionReturn(0); 250*47c6ae99SBarry Smith } 251*47c6ae99SBarry Smith 252*47c6ae99SBarry Smith 253*47c6ae99SBarry Smith #if defined(PETSC_HAVE_HDF5) 254*47c6ae99SBarry Smith #undef __FUNCT__ 255*47c6ae99SBarry Smith #define __FUNCT__ "VecView_MPI_HDF5_DA" 256*47c6ae99SBarry Smith PetscErrorCode VecView_MPI_HDF5_DA(Vec xin,PetscViewer viewer) 257*47c6ae99SBarry Smith { 258*47c6ae99SBarry Smith PetscErrorCode ierr; 259*47c6ae99SBarry Smith DA da; 260*47c6ae99SBarry Smith hsize_t dim,dims[5]; 261*47c6ae99SBarry Smith hsize_t count[5]; 262*47c6ae99SBarry Smith hsize_t offset[5]; 263*47c6ae99SBarry Smith PetscInt cnt = 0; 264*47c6ae99SBarry Smith PetscScalar *x; 265*47c6ae99SBarry Smith const char *vecname; 266*47c6ae99SBarry Smith hid_t filespace; /* file dataspace identifier */ 267*47c6ae99SBarry Smith hid_t plist_id; /* property list identifier */ 268*47c6ae99SBarry Smith hid_t dset_id; /* dataset identifier */ 269*47c6ae99SBarry Smith hid_t memspace; /* memory dataspace identifier */ 270*47c6ae99SBarry Smith hid_t file_id; 271*47c6ae99SBarry Smith herr_t status; 272*47c6ae99SBarry Smith 273*47c6ae99SBarry Smith PetscFunctionBegin; 274*47c6ae99SBarry Smith ierr = PetscViewerHDF5GetFileId(viewer, &file_id);CHKERRQ(ierr); 275*47c6ae99SBarry Smith ierr = PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);CHKERRQ(ierr); 276*47c6ae99SBarry Smith if (!da) SETERRQ(((PetscObject)xin)->comm,PETSC_ERR_ARG_WRONG,"Vector not generated from a DA"); 277*47c6ae99SBarry Smith 278*47c6ae99SBarry Smith /* Create the dataspace for the dataset */ 279*47c6ae99SBarry Smith dim = PetscHDF5IntCast(da->dim + ((da->w == 1) ? 0 : 1)); 280*47c6ae99SBarry Smith if (da->dim == 3) dims[cnt++] = PetscHDF5IntCast(da->P); 281*47c6ae99SBarry Smith if (da->dim > 1) dims[cnt++] = PetscHDF5IntCast(da->N); 282*47c6ae99SBarry Smith dims[cnt++] = PetscHDF5IntCast(da->M); 283*47c6ae99SBarry Smith if (da->w > 1) dims[cnt++] = PetscHDF5IntCast(da->w); 284*47c6ae99SBarry Smith #if defined(PETSC_USE_COMPLEX) 285*47c6ae99SBarry Smith dim++; 286*47c6ae99SBarry Smith dims[cnt++] = 2; 287*47c6ae99SBarry Smith #endif 288*47c6ae99SBarry Smith filespace = H5Screate_simple(dim, dims, NULL); 289*47c6ae99SBarry Smith if (filespace == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot H5Screate_simple()"); 290*47c6ae99SBarry Smith 291*47c6ae99SBarry Smith /* Create the dataset with default properties and close filespace */ 292*47c6ae99SBarry Smith ierr = PetscObjectGetName((PetscObject)xin,&vecname);CHKERRQ(ierr); 293*47c6ae99SBarry Smith #if (H5_VERS_MAJOR * 10000 + H5_VERS_MINOR * 100 + H5_VERS_RELEASE >= 10800) 294*47c6ae99SBarry Smith dset_id = H5Dcreate2(file_id, vecname, H5T_NATIVE_DOUBLE, filespace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); 295*47c6ae99SBarry Smith #else 296*47c6ae99SBarry Smith dset_id = H5Dcreate(file_id, vecname, H5T_NATIVE_DOUBLE, filespace, H5P_DEFAULT); 297*47c6ae99SBarry Smith #endif 298*47c6ae99SBarry Smith if (dset_id == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot H5Dcreate2()"); 299*47c6ae99SBarry Smith status = H5Sclose(filespace);CHKERRQ(status); 300*47c6ae99SBarry Smith 301*47c6ae99SBarry Smith /* Each process defines a dataset and writes it to the hyperslab in the file */ 302*47c6ae99SBarry Smith cnt = 0; 303*47c6ae99SBarry Smith if (da->dim == 3) offset[cnt++] = PetscHDF5IntCast(da->zs); 304*47c6ae99SBarry Smith if (da->dim > 1) offset[cnt++] = PetscHDF5IntCast(da->ys); 305*47c6ae99SBarry Smith offset[cnt++] = PetscHDF5IntCast(da->xs/da->w); 306*47c6ae99SBarry Smith if (da->w > 1) offset[cnt++] = 0; 307*47c6ae99SBarry Smith #if defined(PETSC_USE_COMPLEX) 308*47c6ae99SBarry Smith offset[cnt++] = 0; 309*47c6ae99SBarry Smith #endif 310*47c6ae99SBarry Smith cnt = 0; 311*47c6ae99SBarry Smith if (da->dim == 3) count[cnt++] = PetscHDF5IntCast(da->ze - da->zs); 312*47c6ae99SBarry Smith if (da->dim > 1) count[cnt++] = PetscHDF5IntCast(da->ye - da->ys); 313*47c6ae99SBarry Smith count[cnt++] = PetscHDF5IntCast((da->xe - da->xs)/da->w); 314*47c6ae99SBarry Smith if (da->w > 1) count[cnt++] = PetscHDF5IntCast(da->w); 315*47c6ae99SBarry Smith #if defined(PETSC_USE_COMPLEX) 316*47c6ae99SBarry Smith count[cnt++] = 2; 317*47c6ae99SBarry Smith #endif 318*47c6ae99SBarry Smith memspace = H5Screate_simple(dim, count, NULL); 319*47c6ae99SBarry Smith if (memspace == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot H5Screate_simple()"); 320*47c6ae99SBarry Smith 321*47c6ae99SBarry Smith 322*47c6ae99SBarry Smith filespace = H5Dget_space(dset_id); 323*47c6ae99SBarry Smith if (filespace == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot H5Dget_space()"); 324*47c6ae99SBarry Smith status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, count, NULL);CHKERRQ(status); 325*47c6ae99SBarry Smith 326*47c6ae99SBarry Smith /* Create property list for collective dataset write */ 327*47c6ae99SBarry Smith plist_id = H5Pcreate(H5P_DATASET_XFER); 328*47c6ae99SBarry Smith if (plist_id == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot H5Pcreate()"); 329*47c6ae99SBarry Smith #if defined(PETSC_HAVE_H5PSET_FAPL_MPIO) 330*47c6ae99SBarry Smith status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);CHKERRQ(status); 331*47c6ae99SBarry Smith #endif 332*47c6ae99SBarry Smith /* To write dataset independently use H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT) */ 333*47c6ae99SBarry Smith 334*47c6ae99SBarry Smith ierr = VecGetArray(xin, &x);CHKERRQ(ierr); 335*47c6ae99SBarry Smith status = H5Dwrite(dset_id, H5T_NATIVE_DOUBLE, memspace, filespace, plist_id, x);CHKERRQ(status); 336*47c6ae99SBarry Smith status = H5Fflush(file_id, H5F_SCOPE_GLOBAL);CHKERRQ(status); 337*47c6ae99SBarry Smith ierr = VecRestoreArray(xin, &x);CHKERRQ(ierr); 338*47c6ae99SBarry Smith 339*47c6ae99SBarry Smith /* Close/release resources */ 340*47c6ae99SBarry Smith status = H5Pclose(plist_id);CHKERRQ(status); 341*47c6ae99SBarry Smith status = H5Sclose(filespace);CHKERRQ(status); 342*47c6ae99SBarry Smith status = H5Sclose(memspace);CHKERRQ(status); 343*47c6ae99SBarry Smith status = H5Dclose(dset_id);CHKERRQ(status); 344*47c6ae99SBarry Smith ierr = PetscInfo1(xin,"Wrote Vec object with name %s\n",vecname);CHKERRQ(ierr); 345*47c6ae99SBarry Smith PetscFunctionReturn(0); 346*47c6ae99SBarry Smith } 347*47c6ae99SBarry Smith #endif 348*47c6ae99SBarry Smith 349*47c6ae99SBarry Smith EXTERN PetscErrorCode VecView_MPI_Draw_DA1d(Vec,PetscViewer); 350*47c6ae99SBarry Smith 351*47c6ae99SBarry Smith #if defined(PETSC_HAVE_MPIIO) 352*47c6ae99SBarry Smith #undef __FUNCT__ 353*47c6ae99SBarry Smith #define __FUNCT__ "DAArrayMPIIO" 354*47c6ae99SBarry Smith static PetscErrorCode DAArrayMPIIO(DA da,PetscViewer viewer,Vec xin,PetscBool write) 355*47c6ae99SBarry Smith { 356*47c6ae99SBarry Smith PetscErrorCode ierr; 357*47c6ae99SBarry Smith MPI_File mfdes; 358*47c6ae99SBarry Smith PetscMPIInt gsizes[4],lsizes[4],lstarts[4],asiz,dof; 359*47c6ae99SBarry Smith MPI_Datatype view; 360*47c6ae99SBarry Smith const PetscScalar *array; 361*47c6ae99SBarry Smith MPI_Offset off; 362*47c6ae99SBarry Smith MPI_Aint ub,ul; 363*47c6ae99SBarry Smith PetscInt type,rows,vecrows,tr[2]; 364*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 365*47c6ae99SBarry Smith 366*47c6ae99SBarry Smith PetscFunctionBegin; 367*47c6ae99SBarry Smith ierr = VecGetSize(xin,&vecrows);CHKERRQ(ierr); 368*47c6ae99SBarry Smith if (!write) { 369*47c6ae99SBarry Smith /* Read vector header. */ 370*47c6ae99SBarry Smith ierr = PetscViewerBinaryRead(viewer,tr,2,PETSC_INT);CHKERRQ(ierr); 371*47c6ae99SBarry Smith type = tr[0]; 372*47c6ae99SBarry Smith rows = tr[1]; 373*47c6ae99SBarry Smith if (type != VEC_FILE_CLASSID) SETERRQ(((PetscObject)da)->comm,PETSC_ERR_ARG_WRONG,"Not vector next in file"); 374*47c6ae99SBarry Smith if (rows != vecrows) SETERRQ(((PetscObject)da)->comm,PETSC_ERR_ARG_SIZ,"Vector in file not same size as DA vector"); 375*47c6ae99SBarry Smith } else { 376*47c6ae99SBarry Smith tr[0] = VEC_FILE_CLASSID; 377*47c6ae99SBarry Smith tr[1] = vecrows; 378*47c6ae99SBarry Smith ierr = PetscViewerBinaryWrite(viewer,tr,2,PETSC_INT,PETSC_TRUE);CHKERRQ(ierr); 379*47c6ae99SBarry Smith } 380*47c6ae99SBarry Smith 381*47c6ae99SBarry Smith dof = PetscMPIIntCast(dd->w); 382*47c6ae99SBarry Smith gsizes[0] = dof; gsizes[1] = PetscMPIIntCast(dd->M); gsizes[2] = PetscMPIIntCast(dd->N); gsizes[3] = PetscMPIIntCast(dd->P); 383*47c6ae99SBarry Smith lsizes[0] = dof;lsizes[1] = PetscMPIIntCast((dd->xe-dd->xs)/dof); lsizes[2] = PetscMPIIntCast(dd->ye-dd->ys); lsizes[3] = PetscMPIIntCast(dd->ze-dd->zs); 384*47c6ae99SBarry Smith lstarts[0] = 0; lstarts[1] = PetscMPIIntCast(dd->xs/dof); lstarts[2] = PetscMPIIntCast(dd->ys); lstarts[3] = PetscMPIIntCast(dd->zs); 385*47c6ae99SBarry Smith ierr = MPI_Type_create_subarray(dd->dim+1,gsizes,lsizes,lstarts,MPI_ORDER_FORTRAN,MPIU_SCALAR,&view);CHKERRQ(ierr); 386*47c6ae99SBarry Smith ierr = MPI_Type_commit(&view);CHKERRQ(ierr); 387*47c6ae99SBarry Smith 388*47c6ae99SBarry Smith ierr = PetscViewerBinaryGetMPIIODescriptor(viewer,&mfdes);CHKERRQ(ierr); 389*47c6ae99SBarry Smith ierr = PetscViewerBinaryGetMPIIOOffset(viewer,&off);CHKERRQ(ierr); 390*47c6ae99SBarry Smith ierr = MPI_File_set_view(mfdes,off,MPIU_SCALAR,view,(char *)"native",MPI_INFO_NULL);CHKERRQ(ierr); 391*47c6ae99SBarry Smith ierr = VecGetArrayRead(xin,&array);CHKERRQ(ierr); 392*47c6ae99SBarry Smith asiz = lsizes[1]*(lsizes[2] > 0 ? lsizes[2] : 1)*(lsizes[3] > 0 ? lsizes[3] : 1)*dof; 393*47c6ae99SBarry Smith if (write) { 394*47c6ae99SBarry Smith ierr = MPIU_File_write_all(mfdes,(PetscScalar*)array,asiz,MPIU_SCALAR,MPI_STATUS_IGNORE);CHKERRQ(ierr); 395*47c6ae99SBarry Smith } else { 396*47c6ae99SBarry Smith ierr = MPIU_File_read_all(mfdes,(PetscScalar*)array,asiz,MPIU_SCALAR,MPI_STATUS_IGNORE);CHKERRQ(ierr); 397*47c6ae99SBarry Smith } 398*47c6ae99SBarry Smith ierr = MPI_Type_get_extent(view,&ul,&ub);CHKERRQ(ierr); 399*47c6ae99SBarry Smith ierr = PetscViewerBinaryAddMPIIOOffset(viewer,ub);CHKERRQ(ierr); 400*47c6ae99SBarry Smith ierr = VecRestoreArrayRead(xin,&array);CHKERRQ(ierr); 401*47c6ae99SBarry Smith ierr = MPI_Type_free(&view);CHKERRQ(ierr); 402*47c6ae99SBarry Smith PetscFunctionReturn(0); 403*47c6ae99SBarry Smith } 404*47c6ae99SBarry Smith #endif 405*47c6ae99SBarry Smith 406*47c6ae99SBarry Smith EXTERN_C_BEGIN 407*47c6ae99SBarry Smith #undef __FUNCT__ 408*47c6ae99SBarry Smith #define __FUNCT__ "VecView_MPI_DA" 409*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT VecView_MPI_DA(Vec xin,PetscViewer viewer) 410*47c6ae99SBarry Smith { 411*47c6ae99SBarry Smith DA da; 412*47c6ae99SBarry Smith PetscErrorCode ierr; 413*47c6ae99SBarry Smith PetscInt dim; 414*47c6ae99SBarry Smith Vec natural; 415*47c6ae99SBarry Smith PetscBool isdraw; 416*47c6ae99SBarry Smith #if defined(PETSC_HAVE_HDF5) 417*47c6ae99SBarry Smith PetscBool ishdf5; 418*47c6ae99SBarry Smith #endif 419*47c6ae99SBarry Smith const char *prefix; 420*47c6ae99SBarry Smith 421*47c6ae99SBarry Smith PetscFunctionBegin; 422*47c6ae99SBarry Smith ierr = PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);CHKERRQ(ierr); 423*47c6ae99SBarry Smith if (!da) SETERRQ(((PetscObject)xin)->comm,PETSC_ERR_ARG_WRONG,"Vector not generated from a DA"); 424*47c6ae99SBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr); 425*47c6ae99SBarry Smith #if defined(PETSC_HAVE_HDF5) 426*47c6ae99SBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERHDF5,&ishdf5);CHKERRQ(ierr); 427*47c6ae99SBarry Smith #endif 428*47c6ae99SBarry Smith if (isdraw) { 429*47c6ae99SBarry Smith ierr = DAGetInfo(da,&dim,0,0,0,0,0,0,0,0,0,0);CHKERRQ(ierr); 430*47c6ae99SBarry Smith if (dim == 1) { 431*47c6ae99SBarry Smith ierr = VecView_MPI_Draw_DA1d(xin,viewer);CHKERRQ(ierr); 432*47c6ae99SBarry Smith } else if (dim == 2) { 433*47c6ae99SBarry Smith ierr = VecView_MPI_Draw_DA2d(xin,viewer);CHKERRQ(ierr); 434*47c6ae99SBarry Smith } else { 435*47c6ae99SBarry Smith SETERRQ1(((PetscObject)da)->comm,PETSC_ERR_SUP,"Cannot graphically view vector associated with this dimensional DA %D",dim); 436*47c6ae99SBarry Smith } 437*47c6ae99SBarry Smith #if defined(PETSC_HAVE_HDF5) 438*47c6ae99SBarry Smith } else if (ishdf5) { 439*47c6ae99SBarry Smith ierr = VecView_MPI_HDF5_DA(xin,viewer);CHKERRQ(ierr); 440*47c6ae99SBarry Smith #endif 441*47c6ae99SBarry Smith } else { 442*47c6ae99SBarry Smith #if defined(PETSC_HAVE_MPIIO) 443*47c6ae99SBarry Smith PetscBool isbinary,isMPIIO; 444*47c6ae99SBarry Smith 445*47c6ae99SBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 446*47c6ae99SBarry Smith if (isbinary) { 447*47c6ae99SBarry Smith ierr = PetscViewerBinaryGetMPIIO(viewer,&isMPIIO);CHKERRQ(ierr); 448*47c6ae99SBarry Smith if (isMPIIO) { 449*47c6ae99SBarry Smith ierr = DAArrayMPIIO(da,viewer,xin,PETSC_TRUE);CHKERRQ(ierr); 450*47c6ae99SBarry Smith PetscFunctionReturn(0); 451*47c6ae99SBarry Smith } 452*47c6ae99SBarry Smith } 453*47c6ae99SBarry Smith #endif 454*47c6ae99SBarry Smith 455*47c6ae99SBarry Smith /* call viewer on natural ordering */ 456*47c6ae99SBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)xin,&prefix);CHKERRQ(ierr); 457*47c6ae99SBarry Smith ierr = DACreateNaturalVector(da,&natural);CHKERRQ(ierr); 458*47c6ae99SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)natural,prefix);CHKERRQ(ierr); 459*47c6ae99SBarry Smith ierr = DAGlobalToNaturalBegin(da,xin,INSERT_VALUES,natural);CHKERRQ(ierr); 460*47c6ae99SBarry Smith ierr = DAGlobalToNaturalEnd(da,xin,INSERT_VALUES,natural);CHKERRQ(ierr); 461*47c6ae99SBarry Smith ierr = PetscObjectSetName((PetscObject)natural,((PetscObject)xin)->name);CHKERRQ(ierr); 462*47c6ae99SBarry Smith ierr = VecView(natural,viewer);CHKERRQ(ierr); 463*47c6ae99SBarry Smith ierr = VecDestroy(natural);CHKERRQ(ierr); 464*47c6ae99SBarry Smith } 465*47c6ae99SBarry Smith PetscFunctionReturn(0); 466*47c6ae99SBarry Smith } 467*47c6ae99SBarry Smith EXTERN_C_END 468*47c6ae99SBarry Smith 469*47c6ae99SBarry Smith #if defined(PETSC_HAVE_HDF5) 470*47c6ae99SBarry Smith #undef __FUNCT__ 471*47c6ae99SBarry Smith #define __FUNCT__ "VecLoad_HDF5_DA" 472*47c6ae99SBarry Smith PetscErrorCode VecLoad_HDF5_DA(Vec xin, PetscViewer viewer) 473*47c6ae99SBarry Smith { 474*47c6ae99SBarry Smith DA da; 475*47c6ae99SBarry Smith PetscErrorCode ierr; 476*47c6ae99SBarry Smith hsize_t dim,dims[5]; 477*47c6ae99SBarry Smith hsize_t count[5]; 478*47c6ae99SBarry Smith hsize_t offset[5]; 479*47c6ae99SBarry Smith PetscInt cnt = 0; 480*47c6ae99SBarry Smith PetscScalar *x; 481*47c6ae99SBarry Smith const char *vecname; 482*47c6ae99SBarry Smith hid_t filespace; /* file dataspace identifier */ 483*47c6ae99SBarry Smith hid_t plist_id; /* property list identifier */ 484*47c6ae99SBarry Smith hid_t dset_id; /* dataset identifier */ 485*47c6ae99SBarry Smith hid_t memspace; /* memory dataspace identifier */ 486*47c6ae99SBarry Smith hid_t file_id; 487*47c6ae99SBarry Smith herr_t status; 488*47c6ae99SBarry Smith DM_DA *dd = (DM_DA*)da->data; 489*47c6ae99SBarry Smith 490*47c6ae99SBarry Smith PetscFunctionBegin; 491*47c6ae99SBarry Smith ierr = PetscViewerHDF5GetFileId(viewer, &file_id);CHKERRQ(ierr); 492*47c6ae99SBarry Smith ierr = PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);CHKERRQ(ierr); 493*47c6ae99SBarry Smith 494*47c6ae99SBarry Smith /* Create the dataspace for the dataset */ 495*47c6ae99SBarry Smith dim = PetscHDF5IntCast(dd->dim + ((dd->w == 1) ? 0 : 1)); 496*47c6ae99SBarry Smith if (dd->dim == 3) dims[cnt++] = PetscHDF5IntCast(dd->P); 497*47c6ae99SBarry Smith if (dd->dim > 1) dims[cnt++] = PetscHDF5IntCast(dd->N); 498*47c6ae99SBarry Smith dims[cnt++] = PetscHDF5IntCast(dd->M); 499*47c6ae99SBarry Smith if (dd->w > 1) PetscHDF5IntCast(dims[cnt++] = dd->w); 500*47c6ae99SBarry Smith #if defined(PETSC_USE_COMPLEX) 501*47c6ae99SBarry Smith dim++; 502*47c6ae99SBarry Smith dims[cnt++] = 2; 503*47c6ae99SBarry Smith #endif 504*47c6ae99SBarry Smith 505*47c6ae99SBarry Smith /* Create the dataset with default properties and close filespace */ 506*47c6ae99SBarry Smith ierr = PetscObjectGetName((PetscObject)xin,&vecname);CHKERRQ(ierr); 507*47c6ae99SBarry Smith #if (H5_VERS_MAJOR * 10000 + H5_VERS_MINOR * 100 + H5_VERS_RELEASE >= 10800) 508*47c6ae99SBarry Smith dset_id = H5Dopen2(file_id, vecname, H5P_DEFAULT); 509*47c6ae99SBarry Smith #else 510*47c6ae99SBarry Smith dset_id = H5Dopen(file_id, vecname); 511*47c6ae99SBarry Smith #endif 512*47c6ae99SBarry Smith if (dset_id == -1) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot H5Dopen2() with Vec named %s",vecname); 513*47c6ae99SBarry Smith filespace = H5Dget_space(dset_id); 514*47c6ae99SBarry Smith 515*47c6ae99SBarry Smith /* Each process defines a dataset and reads it from the hyperslab in the file */ 516*47c6ae99SBarry Smith cnt = 0; 517*47c6ae99SBarry Smith if (dd->dim == 3) offset[cnt++] = PetscHDF5IntCast(dd->zs); 518*47c6ae99SBarry Smith if (dd->dim > 1) offset[cnt++] = PetscHDF5IntCast(dd->ys); 519*47c6ae99SBarry Smith offset[cnt++] = PetscHDF5IntCast(dd->xs/dd->w); 520*47c6ae99SBarry Smith if (dd->w > 1) offset[cnt++] = 0; 521*47c6ae99SBarry Smith #if defined(PETSC_USE_COMPLEX) 522*47c6ae99SBarry Smith offset[cnt++] = 0; 523*47c6ae99SBarry Smith #endif 524*47c6ae99SBarry Smith cnt = 0; 525*47c6ae99SBarry Smith if (dd->dim == 3) count[cnt++] = PetscHDF5IntCast(dd->ze - dd->zs); 526*47c6ae99SBarry Smith if (dd->dim > 1) count[cnt++] = PetscHDF5IntCast(dd->ye - dd->ys); 527*47c6ae99SBarry Smith count[cnt++] = PetscHDF5IntCast((dd->xe - dd->xs)/dd->w); 528*47c6ae99SBarry Smith if (dd->w > 1) count[cnt++] = PetscHDF5IntCast(dd->w); 529*47c6ae99SBarry Smith #if defined(PETSC_USE_COMPLEX) 530*47c6ae99SBarry Smith count[cnt++] = 2; 531*47c6ae99SBarry Smith #endif 532*47c6ae99SBarry Smith memspace = H5Screate_simple(dim, count, NULL); 533*47c6ae99SBarry Smith if (memspace == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot H5Screate_simple()"); 534*47c6ae99SBarry Smith 535*47c6ae99SBarry Smith status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, count, NULL);CHKERRQ(status); 536*47c6ae99SBarry Smith 537*47c6ae99SBarry Smith /* Create property list for collective dataset write */ 538*47c6ae99SBarry Smith plist_id = H5Pcreate(H5P_DATASET_XFER); 539*47c6ae99SBarry Smith if (plist_id == -1) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Cannot H5Pcreate()"); 540*47c6ae99SBarry Smith #if defined(PETSC_HAVE_H5PSET_FAPL_MPIO) 541*47c6ae99SBarry Smith status = H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_COLLECTIVE);CHKERRQ(status); 542*47c6ae99SBarry Smith #endif 543*47c6ae99SBarry Smith /* To write dataset independently use H5Pset_dxpl_mpio(plist_id, H5FD_MPIO_INDEPENDENT) */ 544*47c6ae99SBarry Smith 545*47c6ae99SBarry Smith ierr = VecGetArray(xin, &x);CHKERRQ(ierr); 546*47c6ae99SBarry Smith status = H5Dread(dset_id, H5T_NATIVE_DOUBLE, memspace, filespace, plist_id, x);CHKERRQ(status); 547*47c6ae99SBarry Smith ierr = VecRestoreArray(xin, &x);CHKERRQ(ierr); 548*47c6ae99SBarry Smith 549*47c6ae99SBarry Smith /* Close/release resources */ 550*47c6ae99SBarry Smith status = H5Pclose(plist_id);CHKERRQ(status); 551*47c6ae99SBarry Smith status = H5Sclose(filespace);CHKERRQ(status); 552*47c6ae99SBarry Smith status = H5Sclose(memspace);CHKERRQ(status); 553*47c6ae99SBarry Smith status = H5Dclose(dset_id);CHKERRQ(status); 554*47c6ae99SBarry Smith PetscFunctionReturn(0); 555*47c6ae99SBarry Smith } 556*47c6ae99SBarry Smith #endif 557*47c6ae99SBarry Smith 558*47c6ae99SBarry Smith #undef __FUNCT__ 559*47c6ae99SBarry Smith #define __FUNCT__ "VecLoad_Binary_DA" 560*47c6ae99SBarry Smith PetscErrorCode VecLoad_Binary_DA(Vec xin, PetscViewer viewer) 561*47c6ae99SBarry Smith { 562*47c6ae99SBarry Smith DA da; 563*47c6ae99SBarry Smith PetscErrorCode ierr; 564*47c6ae99SBarry Smith Vec natural; 565*47c6ae99SBarry Smith const char *prefix; 566*47c6ae99SBarry Smith PetscInt bs; 567*47c6ae99SBarry Smith PetscBool flag; 568*47c6ae99SBarry Smith DM_DA *dd; 569*47c6ae99SBarry Smith #if defined(PETSC_HAVE_MPIIO) 570*47c6ae99SBarry Smith PetscBool isMPIIO; 571*47c6ae99SBarry Smith #endif 572*47c6ae99SBarry Smith 573*47c6ae99SBarry Smith PetscFunctionBegin; 574*47c6ae99SBarry Smith ierr = PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);CHKERRQ(ierr); 575*47c6ae99SBarry Smith dd = (DM_DA*)da->data; 576*47c6ae99SBarry Smith #if defined(PETSC_HAVE_MPIIO) 577*47c6ae99SBarry Smith ierr = PetscViewerBinaryGetMPIIO(viewer,&isMPIIO);CHKERRQ(ierr); 578*47c6ae99SBarry Smith if (isMPIIO) { 579*47c6ae99SBarry Smith ierr = DAArrayMPIIO(da,viewer,xin,PETSC_FALSE);CHKERRQ(ierr); 580*47c6ae99SBarry Smith PetscFunctionReturn(0); 581*47c6ae99SBarry Smith } 582*47c6ae99SBarry Smith #endif 583*47c6ae99SBarry Smith 584*47c6ae99SBarry Smith ierr = PetscObjectGetOptionsPrefix((PetscObject)xin,&prefix);CHKERRQ(ierr); 585*47c6ae99SBarry Smith ierr = DACreateNaturalVector(da,&natural);CHKERRQ(ierr); 586*47c6ae99SBarry Smith ierr = PetscObjectSetName((PetscObject)natural,((PetscObject)xin)->name);CHKERRQ(ierr); 587*47c6ae99SBarry Smith ierr = PetscObjectSetOptionsPrefix((PetscObject)natural,prefix);CHKERRQ(ierr); 588*47c6ae99SBarry Smith ierr = VecLoad_Binary(natural,viewer);CHKERRQ(ierr); 589*47c6ae99SBarry Smith ierr = DANaturalToGlobalBegin(da,natural,INSERT_VALUES,xin);CHKERRQ(ierr); 590*47c6ae99SBarry Smith ierr = DANaturalToGlobalEnd(da,natural,INSERT_VALUES,xin);CHKERRQ(ierr); 591*47c6ae99SBarry Smith ierr = VecDestroy(natural);CHKERRQ(ierr); 592*47c6ae99SBarry Smith ierr = PetscInfo(xin,"Loading vector from natural ordering into DA\n");CHKERRQ(ierr); 593*47c6ae99SBarry Smith ierr = PetscOptionsGetInt(((PetscObject)xin)->prefix,"-vecload_block_size",&bs,&flag);CHKERRQ(ierr); 594*47c6ae99SBarry Smith if (flag && bs != dd->w) { 595*47c6ae99SBarry Smith ierr = PetscInfo2(xin,"Block size in file %D not equal to DA's dof %D\n",bs,dd->w);CHKERRQ(ierr); 596*47c6ae99SBarry Smith } 597*47c6ae99SBarry Smith PetscFunctionReturn(0); 598*47c6ae99SBarry Smith } 599*47c6ae99SBarry Smith 600*47c6ae99SBarry Smith EXTERN_C_BEGIN 601*47c6ae99SBarry Smith #undef __FUNCT__ 602*47c6ae99SBarry Smith #define __FUNCT__ "VecLoad_Default_DA" 603*47c6ae99SBarry Smith PetscErrorCode PETSCDM_DLLEXPORT VecLoad_Default_DA(Vec xin, PetscViewer viewer) 604*47c6ae99SBarry Smith { 605*47c6ae99SBarry Smith PetscErrorCode ierr; 606*47c6ae99SBarry Smith DA da; 607*47c6ae99SBarry Smith PetscBool isbinary; 608*47c6ae99SBarry Smith #if defined(PETSC_HAVE_HDF5) 609*47c6ae99SBarry Smith PetscBool ishdf5; 610*47c6ae99SBarry Smith #endif 611*47c6ae99SBarry Smith 612*47c6ae99SBarry Smith PetscFunctionBegin; 613*47c6ae99SBarry Smith ierr = PetscObjectQuery((PetscObject)xin,"DA",(PetscObject*)&da);CHKERRQ(ierr); 614*47c6ae99SBarry Smith if (!da) SETERRQ(((PetscObject)xin)->comm,PETSC_ERR_ARG_WRONG,"Vector not generated from a DA"); 615*47c6ae99SBarry Smith 616*47c6ae99SBarry Smith #if defined(PETSC_HAVE_HDF5) 617*47c6ae99SBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERHDF5,&ishdf5);CHKERRQ(ierr); 618*47c6ae99SBarry Smith #endif 619*47c6ae99SBarry Smith ierr = PetscTypeCompare((PetscObject)viewer,PETSCVIEWERBINARY,&isbinary);CHKERRQ(ierr); 620*47c6ae99SBarry Smith 621*47c6ae99SBarry Smith if (isbinary) { 622*47c6ae99SBarry Smith ierr = VecLoad_Binary_DA(xin,viewer);CHKERRQ(ierr); 623*47c6ae99SBarry Smith #if defined(PETSC_HAVE_HDF5) 624*47c6ae99SBarry Smith } else if (ishdf5) { 625*47c6ae99SBarry Smith ierr = VecLoad_HDF5_DA(xin,viewer);CHKERRQ(ierr); 626*47c6ae99SBarry Smith #endif 627*47c6ae99SBarry Smith } else { 628*47c6ae99SBarry Smith SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_SUP,"Viewer type %s not supported for vector loading", ((PetscObject)viewer)->type_name); 629*47c6ae99SBarry Smith } 630*47c6ae99SBarry Smith PetscFunctionReturn(0); 631*47c6ae99SBarry Smith } 632*47c6ae99SBarry Smith EXTERN_C_END 633