FUNCTION CODE vcopy ( FAST struct VARIABLE *vin, /* in: VARIABLE struct to move */ FAST struct VARIABLE *vout /* in: VARIABLE struct to move to */ ) { struct VARIABLE *up; /* unresolved version of p */ struct R_VALID *vdin; /* pointer to 'valid' */ FAST CODE code; if ((*vin).v_class == V_PARM && (*vin).v_iparm) return(FAIL); /* must not copy a RESIDVAR parameter */ up = vin; /* unresolved version of P */ vin = RESOLVE(up); /* resolve indirection */ MOVE_STRUCT(*vin, *vout); /* move structure */ s_copy ((*up).v_name, (*vout).v_name); /* use unresolved name */ (*vout).v_link = NULL; /* end of chain for now */ (*vout).v_default = (*up).v_default; /* in case NAME parm */ /* null out pointers to dynamic memory to avoid double de-allocation */ (*vout).v_pv12 = TRUE; /* flag var built by post V 1.2 TAE */ (*vout).v_qualst.link = NULL; /* qualif symbol table */ if ((*vout).v_class == V_PARM) (*vout).v_tp = NULL; if ((*vout).v_class == V_GLOBAL) (*vout).v_pdf = NULL; (*vout).v_cvp = NULL; (*vout).v_dvp = NULL; (*vout).v_valid = NULL; /* allocate and move values */ if ( ((*vout).v_cvp = (GENPTR) allval(vout)) ==NULL) { overr(); return(FAIL); /* allocation failure */ } code = cpy_val((*vin).v_type, (*vin).v_cvp, (*vout).v_cvp, (*vin).v_count); if (code != SUCCESS) { overr(); return(FAIL); /* allocation failure */ } /* now do the qualifier symbol table (if input variable created by TAE */ /* version which used parameter qualifiers) */ if ((*vin).v_pv12) { code = movest(&(*vin).v_qualst, &(*vout).v_qualst);/* move qual sym tab */ if (code != SUCCESS) { overr(); return(FAIL); /* allocation failure */ } } /* now do valids */ vdin = (struct R_VALID *) (*vin).v_valid; if (vdin != NULL) { if ( ((*vout).v_valid = allleg(vout,(*vdin).count)) ==NULL) /* set defaults */ { overr(); return(FAIL); /* allocation failure */ } cpy_vld((*vin).v_type, (*vin).v_valid, (*vout).v_valid); } return (SUCCESS); }
//--------------------------------------------------------------------- int Wave3d::check(ParVec<int, cpx, PtPrtn>& den, ParVec<int, cpx, PtPrtn>& val, IntNumVec& chkkeys, double& relerr) { #ifndef RELEASE CallStackEntry entry("Wave3d::check"); #endif SAFE_FUNC_EVAL( MPI_Barrier(MPI_COMM_WORLD) ); _self = this; int mpirank = getMPIRank(); ParVec<int, Point3, PtPrtn>& pos = (*_posptr); //1. get pos std::vector<int> all(1,1); std::vector<int> chkkeyvec; for (int i = 0; i < chkkeys.m(); ++i) { chkkeyvec.push_back( chkkeys(i) ); } pos.getBegin(chkkeyvec, all); pos.getEnd(all); std::vector<Point3> tmpsrcpos; for (std::map<int,Point3>::iterator mi = pos.lclmap().begin(); mi != pos.lclmap().end(); ++mi) { if(pos.prtn().owner(mi->first) == mpirank) { tmpsrcpos.push_back(mi->second); } } std::vector<cpx> tmpsrcden; for (std::map<int,cpx>::iterator mi = den.lclmap().begin(); mi != den.lclmap().end(); ++mi) { if(den.prtn().owner(mi->first) == mpirank) { tmpsrcden.push_back(mi->second); } } std::vector<Point3> tmptrgpos; for (int i = 0; i < chkkeyvec.size(); ++i) { tmptrgpos.push_back( pos.access(chkkeyvec[i]) ); } DblNumMat srcpos(3, tmpsrcpos.size(), false, (double*)&(tmpsrcpos[0])); CpxNumVec srcden(tmpsrcden.size(), false, (cpx*)&(tmpsrcden[0])); DblNumMat trgpos(3, tmptrgpos.size(), false, (double*)&(tmptrgpos[0])); CpxNumVec trgval(tmptrgpos.size()); CpxNumMat inter; SAFE_FUNC_EVAL( _kernel.kernel(trgpos, srcpos, srcpos, inter) ); // If no points were assigned to this processor, then the trgval // should be zero. if (inter.n() != 0) { SAFE_FUNC_EVAL( zgemv(1.0, inter, srcden, 0.0, trgval) ); } else { for (int i = 0; i < trgval.m(); ++i) { trgval(i) = 0; } } CpxNumVec allval(trgval.m()); SAFE_FUNC_EVAL( MPI_Barrier(MPI_COMM_WORLD) ); // Note: 2 doubles per complex number SAFE_FUNC_EVAL( MPI_Allreduce(trgval.data(), allval.data(), trgval.m() * 2, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD) ); //2. get val val.getBegin(chkkeyvec, all); val.getEnd(all); CpxNumVec truval(chkkeyvec.size()); for(int i = 0; i < chkkeyvec.size(); ++i) truval(i) = val.access(chkkeyvec[i]); CpxNumVec errval(chkkeyvec.size()); for(int i = 0; i < chkkeyvec.size(); ++i) errval(i) = allval(i) - truval(i); double tn = sqrt( energy(truval) ); double en = sqrt( energy(errval) ); relerr = en / tn; SAFE_FUNC_EVAL( MPI_Barrier(MPI_COMM_WORLD) ); return 0; }