#include #include "MPIO.hh" MPIO::MPIO(IEEEIO *io, MPIcomm &c):file(io),comm(c),sendreq(0){ for(int i=0;i<3;i++) globaldims[i]=localdims[i]=localorigin[i]=0; myid=comm.rank(); int *rootarray=0; if(!myid) rootarray=new int[comm.numProcs()]; int hasfile= file?1:0; comm.gather(0,1,&hasfile,rootarray); if(!myid){ int count,p; for(count=0,p=0;p1){ fprintf(stderr,"MPIO only accepts a single IO node right now.\n"); fprintf(stderr,"You chose %u io nodes\n",count); fprintf(stderr,"I will select only the first one\n"); } } for(int i=0;i<3;i++) slicebuffer[i]=0; for(int i=0;i<2;i++) recvreq[i]=0; comm.bcast(0,root); // tell everyone which proc is root if(rootarray) {delete rootarray; rootarray=0;} } MPIO::~MPIO(){} void MPIO::setLocalDims(int rank,int *origin, int *dims){ if(rank!=3) perror("MPIO is only for 3D IO for now (sorry)!"); if(sendreq) { puts("Bad move!!! Die!!!"); exit(0); } // now check to see if anything has changed // actually we still need to do this collection because we // don't know if something might have changed on some other processor // URK... allorigins = new int[3*comm.numProcs()]; alldims = new int[3*comm.numProcs()]; for(int i=0;i<3;i++) { //printf("localdims-n-origin[%u] = %u:%u\n",i,dims[i],origin[i]); localdims[i]=dims[i]; localorigin[i]=origin[i]; } for(int i=0;ireserveStream(IObase::Float32,3,globaldims); } for(int i=1;iwriteStream(slicebuffer[2],globaldims[0]*globaldims[1]); } } if(isRoot()){ int n = globaldims[2]-1; waitForSlice(n,slicebuffer[(n)%2],slicebuffer[2],recvreq[(n)%2]); file->writeStream(slicebuffer[2],globaldims[0]*globaldims[1]); // do requestfree (double-buffered request free-s) //for(int i=0;i<3;i++) delete slicebuffer[i]; // free everything up //for(int i=0;i<2;i++) delete recvreq[i]; } //**** At end (matching deletes) **** // fprintf(stderr,"Cleanup proc %u\n",myid); // comm.print("Cleanup"); for(int n=0;n=localdims[2]) return; // fprintf(stderr,"\tSendSlice: Proc %u Slice %u sndindex=%u\n", // myid,z,lz); comm.iSend(root,z, localdims[0]*localdims[1], // size of the data data+localdims[0]*localdims[1]*lz,req[lz]); } int MPIO::requestSlice(int z,float *slicebuf, MPI_Request *req){ if(!isRoot()) return 0; // only root performs this operation // for every processor that intersects this slice boundary, // make a request for the contents of that slice! int reqindex =0; for(int offset=0,p=0;p=origin[2] && z=origin[2] && z