INT NS_DIM_PREFIX dematset (MULTIGRID *mg, INT fl, INT tl, INT mode, EMATDATA_DESC *M, DOUBLE a) { INT i,ret,level; ret=dmatset(mg,fl,tl,mode,M->mm,a); if (ret!=NUM_OK) return ret; for (i=0; i<M->n; i++) { ret=dset(mg,fl,tl,mode,M->me[i],a); if (ret!=NUM_OK) return ret; ret=dset(mg,fl,tl,mode,M->em[i],a); if (ret!=NUM_OK) return ret; } for (level=fl; level<=tl; level++) for (i=0; i<M->n*M->n; i++) EMDD_EE(M,level,i)=a; return NUM_OK; }
static void setup_aster_kalman_dtrat(ASTER_S *aster, STAR_S *star, const PARMS_S *parms, int idtrat_wfs0){ if(parms->skyc.verbose){ info2("aster %d dtrat_wfs0=%3d, dtrat=", aster->iaster, (int)parms->skyc.dtrats->p[idtrat_wfs0]); } for(int iwfs=0; iwfs<aster->nwfs; iwfs++){ int idtrat=idtrat_wfs0; if(iwfs>0){ /*don't allow snr to fall below 3.*/ while(idtrat>0 && (aster->wfs[iwfs].pistat->snr->p[idtrat]<3 || (int)parms->skyc.dtrats->p[idtrat] % (int)aster->dtrats->p[0]!=0)){ idtrat--; } } aster->idtrats->p[iwfs]=idtrat; aster->dtrats->p[iwfs]=parms->skyc.dtrats->p[idtrat]; int ng=aster->g->p[iwfs]->nx; if(idtrat>-1){ for(int ig=0; ig<ng; ig++){ aster->neam[0]->p[iwfs+aster->nwfs*iwfs]->p[ig*(ng+1)]= pow(aster->wfs[iwfs].pistat->sanea->p[idtrat]->p[ig], 2); } }else{//no star available dset(aster->neam[0]->p[iwfs+aster->nwfs*iwfs], 0); } if(parms->skyc.verbose){ info2("%3d ", (int)parms->skyc.dtrats->p[idtrat]); } }//for iwfs }
/* * dnewcwd - make a new directory in the loop the current one */ static void dnewcwd(struct directory *dp, int dflag) { int print; if (adrof(STRdunique)) { struct directory *dn; for (dn = dhead.di_prev; dn != &dhead; dn = dn->di_prev) if (dn != dp && Strcmp(dn->di_name, dp->di_name) == 0) { dn->di_next->di_prev = dn->di_prev; dn->di_prev->di_next = dn->di_next; dfree(dn); break; } } dcwd = dp; dset(dcwd->di_name); dgetstack(); print = printd; /* if printd is set, print dirstack... */ if (adrof(STRpushdsilent)) /* but pushdsilent overrides printd... */ print = 0; if (dflag & DIR_PRINT) /* but DIR_PRINT overrides pushdsilent... */ print = 1; if (bequiet) /* and bequiet overrides everything */ print = 0; if (print) printdirs(dflag); cwd_cmd(); /* PWP: run the defined cwd command */ }
static INT NLGSStep (NP_NL_SMOOTHER *theNP, INT level, VECDATA_DESC *x, VECDATA_DESC *b, VECDATA_DESC *c, MATDATA_DESC *A, MATDATA_DESC *L, INT *result) { NP_NLGS *nlgs; NP_NL_ASSEMBLE *ass; MULTIGRID *mg; INT i; nlgs = (NP_NLGS*) theNP; ass = nlgs->smoother.iter.Assemble; mg = nlgs->smoother.iter.base.mg; /* iterate */ dmatset(mg,level,level,ALL_VECTORS,A,0.0); dset (mg,level,level,ALL_VECTORS,theNP->c,0.0); for (i=0; i<nlgs->niter; i++) { if (l_nlgs(nlgs,ass,NP_GRID(theNP,level),theNP->damp,x,theNP->c,A,b) != NUM_OK) NP_RETURN(1,result[0]); } return (0); }
inline typename boost::enable_if<is_multi_array<T>, void>::type write_dataset(h5xxObject const& object, std::string const& name, T const& value, dataspace const& memspace, dataspace const& filespace) { dataset dset(object, name); write_dataset(dset, value, memspace, filespace); }
/* * dnewcwd - make a new directory in the loop the current one */ static void dnewcwd(struct directory *dp) { dcwd = dp; dset(dcwd->di_name); if (printd && !(adrof(STRpushdsilent))) printdirs(); }
INT NS_DIM_PREFIX deset (MULTIGRID *mg, INT fl, INT tl, INT mode, EVECDATA_DESC *x, DOUBLE a) { INT i,ret,level; ret=dset(mg,fl,tl,mode,x->vd,a); if (ret!=NUM_OK) return ret; for (level=fl; level<=tl; level++) for (i=0; i<x->n; i++) EVDD_E(x,level,i)=a; return NUM_OK; }
static void test_cov(){/*not good */ rand_t rstat; int seed=4; double r0=0.2; double dx=1./64; long N=1+1024; long nx=N; long ny=N; long nframe=1; seed_rand(&rstat, seed); map_t *atm=mapnew(nx, ny, dx,dx, NULL); cmat *atmhat=cnew((N+1)*3,(N+1)*3); dmat *atmhattot=dnew((N+1)*3,(N+1)*3); //cfft2plan(atmhat,-1); //cfft2plan(atmhat, 1); dset((dmat*)atm,1); cembedd(atmhat, (dmat*)atm, 0); cfft2(atmhat, -1); cabs22d(&atmhattot, 1, atmhat, 1); ccpd(&atmhat, atmhattot); cfft2i(atmhat, 1); cfftshift(atmhat); dmat *denom=dnew((N+1)*3,(N+1)*3); dmat *cov=dnew((N+1)*3,(N+1)*3); creal2d(&denom, 0, atmhat, 1); writebin(denom, "denom.bin"); dzero(atmhattot); for(long i=0; i<nframe; i++){ info("%ld of %ld\n", i, nframe); for(long j=0; j<nx*ny; j++){ atm->p[j]=randn(&rstat); } fractal_do((dmat*)atm, dx, r0,L0,ninit); /*mapwrite(atm, "atm_%ld.bin", i); */ cembedd(atmhat, (dmat*)atm, 0); cfft2(atmhat, -1); cabs22d(&atmhattot, 1, atmhat, 1); if(i==0 || (i+1)%10==0){ dscale(atmhattot, 1./(i+1)); ccpd(&atmhat, atmhattot); writebin(atmhattot, "atm_psf_%ld.bin",i+1); cfft2i(atmhat, 1); cfftshift(atmhat); creal2d(&cov, 0, atmhat, 1); for(long k=0; k<cov->nx*cov->ny; k++){ cov->p[k]/=denom->p[k]; } writebin(cov, "atm_cov_%ld.bin",i+1); } } }
int main(int argc, char* argv[]) { google::ParseCommandLineFlags(&argc, &argv, true); google::InitGoogleLogging(argv[0]); LOG(INFO) << "Running..."; nicopp::DataSet dset(std::move(nicopp::DataSet::Load("compiled/tagf","compiled/vf","compiled/linkf"))); #ifdef DEBUG ProfilerStart ("prof.out"); #endif /*{ long t = std::clock(); bool run = true; Graph g; g.total_weight = totalLink; int degreeTotal = 0; for(unsigned int i=0;i<nodes.size();i++){ nicopp::Node& node = nodes[i]; degreeTotal += node.neighbors().size(); g.degrees.emplace_back(degreeTotal); for(auto& kv : node.neighbors()){ g.links.emplace_back(kv.first); g.weights.emplace_back(kv.second); } } g.nb_links = g.links.size(); g.nb_nodes = nodes.size(); for(;run;){ int from = g.degrees.size(); Community c(g, 10, 0); LOG(INFO) << g.degrees.size() << " / " << g.links.size() << " / " << g.weights.size() << " <> " << c.size; run = c.one_level(); g = c.partition2graph_binary(); LOG(INFO) << from << " -> " << g.degrees.size() << " Nodes"; } LOG(INFO) << "Lap: " << (std::clock() - t); }*/ { long t = std::clock(); nicopp::TagGraph graph = dset.searchTag(0, 99999999999, 150000); for(int i=0;i<5;i++){ LOG(INFO) << graph.nodes().size() << " nodes / " << graph.edges() << " edges"; graph = std::move(graph.nextLevel(4, .0)); } LOG(INFO) << "Lap: " << (std::clock() - t); for (auto const& node : graph.nodes()){ LOG(INFO) << " Node: " << dset.tag(node.payload().tagId) << " / "<< node.selfLoops() << "/"<<node.degree(); } } #ifdef DEBUG ProfilerStop (); #endif return 0; }
void dtilde(void) { struct directory *d = dcwd; do { if (d == &dhead) continue; d->di_name = dcanon(d->di_name, STRNULL); } while ((d = d->di_prev) != dcwd); dset(dcwd->di_name); }
OutputIterator kruskal_mst_impl(const Graph& G, OutputIterator spanning_tree_edges, Rank rank, Parent parent, Weight weight) { if (num_vertices(G) == 0) return spanning_tree_edges; // Nothing to do in this case typedef typename graph_traits<Graph>::vertex_descriptor Vertex; typedef typename graph_traits<Graph>::edge_descriptor Edge; function_requires<VertexListGraphConcept<Graph> >(); function_requires<EdgeListGraphConcept<Graph> >(); function_requires<OutputIteratorConcept<OutputIterator, Edge> >(); function_requires<ReadWritePropertyMapConcept<Rank, Vertex> >(); function_requires<ReadWritePropertyMapConcept<Parent, Vertex> >(); function_requires<ReadablePropertyMapConcept<Weight, Edge> >(); typedef typename property_traits<Weight>::value_type W_value; typedef typename property_traits<Rank>::value_type R_value; typedef typename property_traits<Parent>::value_type P_value; function_requires<ComparableConcept<W_value> >(); function_requires<ConvertibleConcept<P_value, Vertex> >(); function_requires<IntegerConcept<R_value> >(); disjoint_sets<Rank, Parent> dset(rank, parent); typename graph_traits<Graph>::vertex_iterator ui, uiend; for (boost::tie(ui, uiend) = vertices(G); ui != uiend; ++ui) dset.make_set(*ui); typedef indirect_cmp<Weight, std::greater<W_value> > weight_greater; weight_greater wl(weight); std::priority_queue<Edge, std::vector<Edge>, weight_greater> Q(wl); /*push all edge into Q*/ typename graph_traits<Graph>::edge_iterator ei, eiend; for (boost::tie(ei, eiend) = edges(G); ei != eiend; ++ei) Q.push(*ei); while (! Q.empty()) { Edge e = Q.top(); Q.pop(); Vertex u = dset.find_set(source(e, G)); Vertex v = dset.find_set(target(e, G)); if ( u != v ) { *spanning_tree_edges++ = e; dset.link(u, v); } } return spanning_tree_edges; }
static INT NonLinearDefect (MULTIGRID *mg, INT level, INT init, VECDATA_DESC *x, NP_NEWTON *newton, NP_NL_ASSEMBLE *ass, VEC_SCALAR defect, INT *error) { LRESULT lr; /* result of linear solver */ INT i,n_unk; n_unk = VD_NCOMP(x); /* project solution to all grid levels */ if (newton->trans->PreProcessProject!=NULL) if ((*newton->trans->PreProcessProject)(newton->trans,0,level,error)) { *error = __LINE__; REP_ERR_RETURN(*error); } if ((*newton->trans->ProjectSolution)(newton->trans,0,level,x,error)) { *error = __LINE__; REP_ERR_RETURN(*error); } if (newton->trans->PostProcessProject!=NULL) if ((*newton->trans->PostProcessProject)(newton->trans,0,level,error)) { *error = __LINE__; REP_ERR_RETURN(*error); } if (init) { /* preprocess assemble once before all calls */ if (ass->PreProcess!=NULL) if ((*ass->PreProcess)(ass,0,level,x,error)) { *error = __LINE__; REP_ERR_RETURN(*error); } /* set dirichlet conditions on all grid levels */ if ((*ass->NLAssembleSolution)(ass,0,level,x,error)) { *error = __LINE__; REP_ERR_RETURN(*error); } } /* compute new nonlinear defect */ CSTART(); dset(mg,0,level,ALL_VECTORS,newton->d,0.0); *error = 0; if ((*ass->NLAssembleDefect)(ass,0,level,x,newton->d,newton->J,error)) { *error = __LINE__; REP_ERR_RETURN(*error); } if (*error) return(0); CSTOP(defect_t,defect_c); if (newton->lineSearch == 3) dcopy(mg,0,level,ALL_VECTORS,newton->dsave,newton->d); if (UG_math_error) { UserWrite("math error in NLAssembleDefect\n"); UG_math_error = 0; *error = __LINE__; REP_ERR_RETURN(*error); } IFDEBUG(np,3) UserWrite("---- After computation of nonlinear defect\n"); ListVectorRange(mg,0,level,0,0,1000,FALSE,TRUE,~(INT)1,LV_MOD_DEFAULT); ENDDEBUG /* compute norm of defect */ if ((*newton->solve->Residuum)(newton->solve,0,level,newton->v,newton->d,newton->J,&lr)) { *error = __LINE__; REP_ERR_RETURN(*error); } for (i=0; i<n_unk; i++) defect[i] = lr.last_defect[i]; return (0); }
void RunProof() { std::string filename = "/data/Phys/data/mcd02kpi_tracks9_merged.root"; bool fileNotFound = gSystem->AccessPathName(filename.c_str()); // if local file is not found use the EOS version if (fileNotFound) { filename = "root://eoslhcb.cern.ch//eos/lhcb/user/m/malexand/d2hh/secondariesTagging/mcd02kpi_tracks9_merged.root"; } TChain chain("TrackFilter/DecayTree"); chain.Add(filename.c_str()); TDSet dset(chain); auto p = TProof::Open(""); p->Process(&dset, "RadialSelector.C"); }
static int libvirt_init(backend_context_t *c, config_object_t *config) { virConnectPtr vp; char value[256]; struct libvirt_info *info = NULL; char *uri = NULL; info = malloc(sizeof(*info)); if (!info) return -1; dbg_printf(5, "[%s:%d %s]\n", __FILE__, __LINE__, __FUNCTION__); memset(info, 0, sizeof(*info)); #ifdef _MODULE if (sc_get(config, "fence_virtd/@debug", value, sizeof(value))==0) dset(atoi(value)); #endif if (sc_get(config, "backends/libvirt/@uri", value, sizeof(value)) == 0) { uri = strdup(value); if (!uri) { free(info); return -1; } dbg_printf(1, "Using %s\n", uri); } /* We don't need to store the URI; we only use it once */ vp = virConnectOpen(uri); if (!vp) { free(uri); free(info); return -1; } free(uri); info->magic = MAGIC; info->vp = vp; *c = (void *)info; return 0; }
int main(int argc, char *argv[]) { if(argc<7) { info("Usage: %s loc.bin amp.bin cov.bin ncomp pttr wvl1 wvl2 ...\n", argv[0]); exit(0); } enum { P_EXE, P_LOC, P_AMP, P_COV, P_NCOMP, P_PTTR, P_WVL }; loc_t *loc=locread("%s",argv[P_LOC]); dmat *amp=NULL; if(strcmp(argv[P_AMP],"NULL")) { amp=dread("%s",argv[P_AMP]); } else { amp=dnew(loc->nloc,1); dset(amp,1); } dmat *cov=dread("%s",argv[P_COV]); long ncomp=strtol(argv[P_NCOMP], NULL, 10); long pttr=strtol(argv[P_PTTR], NULL, 10); cmat *otf=otf=cnew(ncomp, ncomp); dmat *psf=NULL; for(int iwvl=0; iwvl<argc-P_WVL; iwvl++) { double wvl=strtod(argv[iwvl+P_WVL], NULL); double dtheta=wvl/(ncomp*loc->dx); genotf(&otf, loc, amp, NULL, NULL, 0, wvl, dtheta, cov, 0, 0, ncomp, ncomp, 1, pttr); writebin(otf, "%s_otf_%g.bin", argv[P_COV], wvl); cfftshift(otf); cfft2i(otf, 1); cfftshift(otf); creal2d(&psf, 0, otf, 1); writebin(psf, "%s_psf_%g.bin", argv[P_COV], wvl); } cfree(otf); dfree(psf); dfree(cov); dfree(amp); locfree(loc); }
static void save_molecular_type(const MolecularTypeBase* mtb, std::vector<std::pair<ParticleID, Voxel> > voxels, H5::Group* group) { const Species species(mtb->species()); boost::scoped_ptr<H5::Group> mtgroup( new H5::Group(group->createGroup(species.serial().c_str()))); h5_species_struct property; property.radius = mtb->radius(); property.D = mtb->D(); const MolecularTypeBase* loc(mtb->location()); if (loc->is_vacant()) std::strcpy(property.location, ""); else std::strcpy(property.location, loc->species().serial().c_str()); property.is_structure = mtb->is_structure() ? 1 : 0; property.dimension = mtb->get_dimension(); H5::CompType property_comp_type(get_property_comp()); mtgroup->createAttribute("property", property_comp_type, H5::DataSpace(H5S_SCALAR)).write(property_comp_type, &property); // Save voxels const Integer num_voxels(voxels.size()); std::size_t vidx(0); boost::scoped_array<h5_voxel_struct> h5_voxel_array(new h5_voxel_struct[num_voxels]); for (std::vector<std::pair<ParticleID, Voxel> >::const_iterator itr(voxels.begin()); itr != voxels.end(); ++itr) { h5_voxel_array[vidx].lot = (*itr).first.lot(); h5_voxel_array[vidx].serial = (*itr).first.serial(); h5_voxel_array[vidx].coordinate = (*itr).second.coordinate(); ++vidx; } H5::CompType voxel_comp_type(get_voxel_comp()); hsize_t dims[] = {num_voxels}; H5::DataSpace dspace(/* RANK= */1, dims); boost::scoped_ptr<H5::DataSet> dset(new H5::DataSet( mtgroup->createDataSet("voxels", voxel_comp_type, dspace))); dset->write(h5_voxel_array.get(), dset->getDataType()); }
static int libvirt_init(backend_context_t *c, config_object_t *config) { virConnectPtr vp; char value[256]; struct libvirt_info *info = NULL; int i = 0; info = malloc(sizeof(*info)); if (!info) return -1; dbg_printf(5, "ENTER [%s:%d %s]\n", __FILE__, __LINE__, __FUNCTION__); memset(info, 0, sizeof(*info)); #ifdef _MODULE if (sc_get(config, "fence_virtd/@debug", value, sizeof(value)) == 0) dset(atoi(value)); #endif do { virConnectPtr *vpl = NULL; char conf_attr[256]; char *uri; if (i != 0) { snprintf(conf_attr, sizeof(conf_attr), "backends/libvirt/@uri%d", i); } else snprintf(conf_attr, sizeof(conf_attr), "backends/libvirt/@uri"); ++i; if (sc_get(config, conf_attr, value, sizeof(value)) != 0) break; uri = value; vp = virConnectOpen(uri); if (!vp) { dbg_printf(1, "[libvirt:INIT] Failed to connect to URI: %s\n", uri); continue; } vpl = realloc(info->vp, sizeof(*info->vp) * (info->vp_count + 1)); if (!vpl) { dbg_printf(1, "[libvirt:INIT] Out of memory allocating URI: %s\n", uri); virConnectClose(vp); continue; } info->vp = vpl; info->vp[info->vp_count++] = vp; if (i > 1) dbg_printf(1, "[libvirt:INIT] Added URI%d %s\n", i - 1, uri); else dbg_printf(1, "[libvirt:INIT] Added URI %s\n", uri); } while (1); if (info->vp_count < 1) { dbg_printf(1, "[libvirt:INIT] Could not connect to any hypervisors\n"); if (info->vp) free(info->vp); free(info); return -1; } info->magic = MAGIC; *c = (void *)info; return 0; }
typename boost::enable_if<is_multi_array<T>, void>::type read_dataset(h5xxObject const& object, std::string const& name, T & array) { dataset dset(object, name); read_dataset(dset, array); }
DevisibleTree(Graph & graph) : graph_(graph) { typedef unordered_map<VertexId, int> RankMap; typedef unordered_map<VertexId, VertexId> ParentMap; typedef boost::associative_property_map<RankMap> BoostRankMap; typedef boost::associative_property_map<ParentMap> BoostParentMap; RankMap rank_map; ParentMap parent_map; BoostRankMap boost_rank_map(rank_map); BoostParentMap boost_parent_map(parent_map); boost::disjoint_sets<BoostRankMap, BoostParentMap> dset(boost_rank_map, boost_parent_map); for (const VertexId& vertex : graph_) { dset.make_set(vertex); } for (const VertexId& vertex : graph_) { nodes_.push_back(Node(vertex)); index_[vertex] = nodes_.size() - 1; } TRACE("Creating tree of size:" << nodes_.size()); // build trees // for (auto it = graph_.SmartEdgeBegin(LengthComparator<Graph>(graph_)); !it.IsEnd(); ++it) { for (VertexId vertex : graph) { for (EdgeId edge : graph.OutgoingEdges(vertex)) { VertexId start = graph_.EdgeStart(edge); VertexId end = graph_.EdgeEnd(edge); VertexId start_root = dset.find_set(start); VertexId end_root = dset.find_set(end); if (start_root != end_root) { dset.link(start_root, end_root); edges_.insert(edge); } } } TRACE("Node quantity: " << nodes_.size()); TRACE("Edges for tree: " << edges_.size()); unordered_set<VertexId> forest_roots; for (VertexId vertex : graph_) { forest_roots.insert(dset.find_set(vertex)); } for (VertexId vertex : forest_roots) { Node& node = GetNode(vertex); TRACE("Adding " << vertex); CreateTree(node, edges_); root_.AddChild(node); } root_.UpdateSubtreeSize(); }
static INT NewtonSolver (NP_NL_SOLVER *nls, INT level, VECDATA_DESC *x, NP_NL_ASSEMBLE *ass, VEC_SCALAR abslimit, VEC_SCALAR reduction, NLRESULT *res) { NP_NEWTON *newton; /* object pointer */ MULTIGRID *mg; /* multigrid from base class */ INT r; /* iteration counter */ INT i,kk; /* some loop counters */ char text[DISPLAY_WIDTH+4]; /* display text in PCR */ INT PrintID; /* print id for PCR */ VEC_SCALAR defect, defect2reach; /* component--wise norm */ VEC_SCALAR defectmax; /* max defect without codivergence */ INT n_unk; /* number of components in solution */ DOUBLE s,sold,sprime,s2reach,sred; /* combined defect norm */ INT reassemble=1; /* adaptive computation of jacobian */ VEC_SCALAR linred; /* parameters for linear solver */ DOUBLE red_factor[MAX_VEC_COMP]; /* convergence factor for linear iter */ DOUBLE la; /* damping factor in line search */ DOUBLE rho[MAX_LINE_SEARCH+1]; /* reduction factors of linesearch */ DOUBLE rhomin; /* best reduction if !accept */ INT best_ls; /* best ls if !accept */ INT accept; /* line search accepted */ INT bl; /* baselevel returned by preprocess */ INT error; /* for return value */ LRESULT lr; /* result of linear solver */ DOUBLE lambda_old; /* last accepted lamda */ DOUBLE lambda_min; /* minimal lamda */ INT use_second; /* get status */ newton = (NP_NEWTON *) nls; /* cast from abstract base class to final class*/ mg = nls->base.mg; UG_math_error = 0; /* fill result variable with error condition */ res->error_code = 0; res->converged = 0; res->rho_first = 0.0; res->number_of_nonlinear_iterations = 0; res->number_of_line_searches = 0; res->total_linear_iterations = 0; res->max_linear_iterations = 0; res->exec_time = 0.0; /* initialize timers and counters */ defect_c = newton_c = linear_c = 0; defect_t = newton_t = linear_t = 0.0; if (newton->lineSearch == 3) { lambda_min = lambda_old = 1.0; for (kk=1; kk<=newton->maxLineSearch; kk++) lambda_min = LINE_SEARCH_REDUCTION * lambda_min; } /* check function pointers in numprocs */ if (ass->NLAssembleSolution==NULL) { UserWrite("Newton: ass->NLAssembleSolution not defined\n"); res->error_code = __LINE__; REP_ERR_RETURN(res->error_code); } if (ass->NLAssembleDefect==NULL) { UserWrite("Newton: ass->NLAssembleDefect not defined\n"); res->error_code = __LINE__; REP_ERR_RETURN(res->error_code); } if (ass->NLAssembleMatrix==NULL) { UserWrite("Newton: ass->NLAssembleMatrix not defined\n"); res->error_code = __LINE__; REP_ERR_RETURN(res->error_code); } /* dynamic XDATA_DESC allocation */ if (ass->A == NULL) ass->A = newton->J; if (AllocVDFromVD(mg,0,level,x, &(newton->v))) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} if (AllocVDFromVD(mg,0,level,x, &(newton->d))) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} if (newton->lineSearch == 3) { if (AllocVDFromVD(mg,0,level,x, &(newton->dold))) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} if (AllocVDFromVD(mg,0,level,x, &(newton->dsave))) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} } /* get number of components */ n_unk = VD_NCOMP(x); /* init ass once and compute nonlinear defect */ if (NonLinearDefect(mg,level,TRUE,x,newton,ass,defect,&error)!=0) { res->error_code = __LINE__; REP_ERR_RETURN(res->error_code); } if (error) goto exit; /* display norm of nonlinear defect */ CenterInPattern(text,DISPLAY_WIDTH,ENVITEM_NAME(newton),'#',"\n"); if (PreparePCR(newton->d,newton->displayMode,text,&PrintID)) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} if (sc_mul(defect2reach,defect,reduction,newton->d)) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} if (sc_mul(defectmax,defect,newton->divFactor,newton->d)) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} use_second=0; for (i=0; i<n_unk; i++) if (defectmax[i]==0.0) use_second=1; if (DoPCR(PrintID,defect,PCR_CRATE)) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} for (i=0; i<n_unk; i++) res->first_defect[i] = defect[i]; /* compute single norm */ s = 0.0; for (i=0; i<n_unk; i++) s += newton->scale[i]*newton->scale[i]*defect[i]*defect[i]; s = sqrt(s); sprime = s; sold = s * sqrt(2.0); sred = 1.0E10; for (i=0; i<n_unk; i++) sred = MIN(sred,reduction[i]); s2reach = s*sred; if (newton->lineSearch) if (newton->displayMode == PCR_FULL_DISPLAY) UserWriteF(" ++ s=%12.4E Initial nonlinear residual\n",s); /* check if iteration is necessary */ if (sc_cmp(defect,abslimit,newton->d) && !newton->force_iteration) { res->converged = 1; for (i=0; i<n_unk; i++) res->last_defect[i] = defect[i]; res->error_code = 0; goto exit; } /* initialize reduction factor for linear solver */ for (i=0; i<n_unk; i++) red_factor[i] = newton->linMinRed[i]; reassemble = 1; /* do newton iterations */ for (r=1; r<=newton->maxit; r++) { if (UG_math_error) { UserWrite("math error before newton loop !\n"); UG_math_error = 0; res->error_code = __LINE__; break; } if (res->converged && newton->force_iteration!=2) break; /* solution already found */ /* compute jacobian */ CSTART(); dset(mg,0,level,ALL_VECTORS,newton->v,0.0); if (reassemble) { if ((*ass->NLAssembleMatrix)(ass,0,level,x,newton->d,newton->v,newton->J,&error)) { res->error_code = __LINE__; REP_ERR_RETURN(res->error_code); } reassemble = 0; } CSTOP(newton_t,newton_c); if (UG_math_error) { UserWrite("math error in NLAssembleMatrix !\n"); UG_math_error = 0; res->error_code = __LINE__; break; } /* solve linear system */ CSTART(); for (i=0; i<n_unk; i++) linred[i] = red_factor[i];bl = 0; if (newton->solve->PreProcess!=NULL) if ((*newton->solve->PreProcess)(newton->solve,level,newton->v,newton->d,newton->J,&bl,&error)) { UserWriteF("NewtonSolver: solve->PreProcess failed, error code %d\n",error); res->error_code = __LINE__; #ifndef ModelP REP_ERR_RETURN (res->error_code); #endif REP_ERR_INC; #ifndef Debug return (res->error_code); #endif } if ((*newton->solve->Residuum)(newton->solve,0,level,newton->v,newton->d,newton->J,&lr)) { res->error_code = __LINE__; goto exit; } if ((*newton->solve->Solver)(newton->solve,level,newton->v,newton->d,newton->J,newton->solve->abslimit,linred,&lr)) { res->error_code = 0; goto exit; } if (newton->solve->PostProcess!=NULL) if ((*newton->solve->PostProcess)(newton->solve,level,newton->v,newton->d,newton->J,&error)) { res->error_code = __LINE__; REP_ERR_RETURN(res->error_code); } CSTOP(linear_t,linear_c); if (UG_math_error) { UG_math_error = 0; res->error_code = __LINE__; } /* if linear solver did not converge, return here */ if (!lr.converged && newton->force_iteration!=2) { UserWrite("\nLinear solver did not converge in Newton method\n"); if (newton->linearRate < 2) { res->error_code = 0; /* no error but exit */ goto exit; /* or goto exit2 ??? */ } } IFDEBUG(np,3) UserWrite("---- After linear solver\n"); ListVectorRange(mg,0,level,0,0,1000,FALSE,TRUE,~(INT)1,LV_MOD_DEFAULT); ENDDEBUG /* linear solver statistics */ res->total_linear_iterations += lr.number_of_linear_iterations; res->max_linear_iterations = MAX(res->max_linear_iterations,lr.number_of_linear_iterations); if (newton->lineSearch) if (newton->displayMode == PCR_FULL_DISPLAY) UserWriteF(" ++ newton step %3d\n",r); /* save current solution for line search */ if (AllocVDFromVD(mg,0,level,x, &(newton->s))) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} dcopy(mg,0,level,ALL_VECTORS,newton->s,x); /* do a line search */ la = newton->lambda; accept=0; for (kk=1; kk<=newton->maxLineSearch; kk++) { /* update solution */ dcopy(mg,0,level,ALL_VECTORS,x,newton->s); daxpy(mg,0,level,ALL_VECTORS,x,-la,newton->v); if (newton->maxit==r && newton->noLastDef) { res->error_code = 0; if (FreeVD(mg,0,level,newton->s)) REP_ERR_RETURN(1); goto exit2; } /* if linear problem: use result of linear solver ! */ if (newton->linearMode) { for (i=0; i<n_unk; i++) defect[i] = lr.last_defect[i]; error = 0; } else if (NonLinearDefect(mg,level,FALSE,x,newton,ass,defect,&error)!=0) { res->error_code = __LINE__; REP_ERR_RETURN(res->error_code); } if (error) goto exit; /* compute single norm */ sold = sprime; sprime = 0.0; for (i=0; i<n_unk; i++) sprime += newton->scale[i]*newton->scale[i]*defect[i]*defect[i]; sprime = sqrt(sprime); rho[kk] = sprime/s; /* print results */ if (newton->lineSearch) if (newton->displayMode == PCR_FULL_DISPLAY) UserWriteF(" ++ ls=%2d, s=%12.4E, rho=%8.4g, lambda= %8.4g\n", kk,sprime,rho[kk],la); if (sprime/s<=1-0.25*fabs(la) || !newton->lineSearch) { lambda_old = la; accept=1; break; } /* else reduce lambda */ la = LINE_SEARCH_REDUCTION*la; } /* if not accepted */ if (!accept) switch (newton->lineSearch) { case 1 : /* break iteration */ UserWrite("line search not accepted, Newton diverged\n"); res->error_code = 0; if (FreeVD(mg,0,level,newton->s)) REP_ERR_RETURN(1); goto exit; case 2 : /* accept best result */ best_ls = 1; rhomin = rho[best_ls]; for (kk=2; kk<=newton->maxLineSearch; kk++) if (rhomin>rho[kk]) { rhomin = rho[kk]; best_ls = kk; } UserWriteF(" ++ accepting linesearch %d\n",best_ls); /* set lambda factor */ la = newton->lambda * pow(LINE_SEARCH_REDUCTION,best_ls-1); lambda_old = la; /* update solution */ dcopy(mg,0,level,ALL_VECTORS,x,newton->s); daxpy(mg,0,level,ALL_VECTORS,x,-la,newton->v); if (NonLinearDefect(mg,level,FALSE,x,newton,ass, defect,&error)!=0) { res->error_code = __LINE__; REP_ERR_RETURN(res->error_code); } if (error) goto exit; break; /*default: accept */ } if (FreeVD(mg,0,level,newton->s)) REP_ERR_RETURN(1); /* print norm of defect */ if (DoPCR(PrintID,defect,PCR_CRATE)) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} /* save convergence of first step, may be used to increase stepsize */ if (r==1) res->rho_first = sprime/s; /* reassemble if nonlinear convergence bad */ if (sprime/s >= newton->rhoReass) reassemble = 1; if (!newton->linearRate) reassemble = 1; /* check convergence of nonlinear iteration */ if (newton->force_iteration!=2) { if (sprime<s2reach) {res->converged=1; break;} if (sc_cmp(defect,abslimit,newton->d)) {res->converged=1; break;} if (sc_cmp(defect,defect2reach,newton->d)) {res->converged=1; break;} } else if (r==newton->maxit) {res->converged=1; break;} if (use_second) { use_second=0; if (sc_mul(defectmax,defect,newton->divFactor,newton->d)) { res->error_code = __LINE__; REP_ERR_RETURN(res->error_code); } } /* else { if (!sc_cmp(defect,defectmax,newton->d)) break; } */ /* compute new reduction factor, assuming quadratic convergence */ for (i=0; i<n_unk; i++) { red_factor[i] = MIN((sprime/s)*(sprime/s),newton->linMinRed[i]); if (newton->linearRate == 1) red_factor[i] = MIN(sprime/s,newton->linMinRed[i]); if (newton->linearRate == 2) red_factor[i] = newton->linMinRed[i]; } /* accept new iterate */ sold = s; s = sprime; } /* print norm of defect */ if (DoPCR(PrintID,defect,PCR_AVERAGE)) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} /* report results and mean execution times */ res->error_code = 0; res->number_of_nonlinear_iterations = newton_c; res->number_of_line_searches = defect_c; for (i=0; i<n_unk; i++) res->last_defect[i] = defect[i]; if (!res->converged) UserWriteF("NL SOLVER: desired convergence not reached\n"); exit2: UserWriteF("AVG EXEC TIMES: DEF[%2d]=%10.4g JAC[%2d]=%10.4g LIN[%2d]=%10.4g\n", defect_c,defect_t/defect_c,newton_c,newton_t/newton_c,linear_c,linear_t/linear_c); res->exec_time = defect_t+newton_t+linear_t; /* postprocess assemble once at the end */ if (ass->PostProcess!=NULL) if ((*ass->PostProcess)(ass,0,level,x,newton->d,newton->J,&error)) { res->error_code = __LINE__; REP_ERR_RETURN(res->error_code); } exit: if (PostPCR(PrintID,NULL)) {res->error_code = __LINE__; REP_ERR_RETURN(res->error_code);} /* deallocate local XDATA_DESCs */ if (FreeVD(mg,0,level,newton->d)) REP_ERR_RETURN(1); if (FreeVD(mg,0,level,newton->v)) REP_ERR_RETURN(1); if (newton->lineSearch == 3) { if (FreeVD(mg,0,level,newton->dold)) REP_ERR_RETURN(1); if (FreeVD(mg,0,level,newton->dsave)) REP_ERR_RETURN(1); } if (res->error_code==0) return (0); else REP_ERR_RETURN (res->error_code); }
static INT EWNSolver (NP_EW_SOLVER *theNP, INT level, INT New, VECDATA_DESC **ev, DOUBLE *ew, NP_NL_ASSEMBLE *Assemble, VEC_SCALAR abslimit, VEC_SCALAR reduction, EWRESULT *ewresult) { NP_EWN *np = (NP_EWN *) theNP; MULTIGRID *theMG = theNP->base.mg; INT i,j,iter,done,result,DoLS; char text[DISPLAY_WIDTH+4],format2[64],format3[64],formatr1[64],formatr2[64],formats[64]; DOUBLE shift,shift_old,cnorm[MAX_NUMBER_EW],norm_x1x2,norm_yx2,norm_yx1,delta; DOUBLE A[MAX_NUMBER_EW][MAX_NUMBER_EW]; DOUBLE B[MAX_NUMBER_EW][MAX_NUMBER_EW]; DOUBLE E[MAX_NUMBER_EW][MAX_NUMBER_EW]; DOUBLE ew_re[MAX_NUMBER_EW],ew_im[MAX_NUMBER_EW]; DOUBLE ew_re_out,ew_im_out; DOUBLE tmp_re[MAX_NUMBER_EW],tmp_im[MAX_NUMBER_EW]; DOUBLE old_re[MAX_NUMBER_EW],old_im[MAX_NUMBER_EW],norm; DOUBLE* table[MAX_NUMBER_EW]; INT index[MAX_NUMBER_EW]; INT bl = 0; ewresult->error_code = 0; CenterInPattern(text,DISPLAY_WIDTH,ENVITEM_NAME(np),'§',"\n"); UserWrite(text); sprintf(text,"%d.%d",np->c_d+1,np->c_d-1); strcpy(formats," %-3d S: % "); strcat(formats,text); strcat(formats,"e\n"); strcpy(format2," %3d: (% "); strcat(format2,text); strcat(format2,"e, % "); strcat(format2,text); strcat(format2,"e)"); strcpy(format3," %3d: [% "); strcat(format3,text); strcat(format3,"e, % "); strcat(format3,text); strcat(format3,"e]"); strcpy(formatr1," %-3d res: %3d: (% "); strcat(formatr1,text); strcat(formatr1,"e, % "); strcat(formatr1,text); strcat(formatr1,"e)\n"); strcpy(formatr2," %3d: (% "); strcat(formatr2,text); strcat(formatr2,"e, % "); strcat(formatr2,text); strcat(formatr2,"e)\n"); shift=np->shift_min; DoLS=0; shift_old=shift-1; for (iter=0; iter<np->maxiter; iter++) { /* preprocess if */ if (iter==0 || DoLS) { if (dmatcopy(theNP->base.mg,bl,level,ALL_VECTORS,np->M,np->N)) return(1); if (dcopy(theNP->base.mg,bl,level,ALL_VECTORS,np->t,np->E)) return(1); if (dscal(theNP->base.mg,bl,level,ALL_VECTORS,np->t,-shift)) return(1); if (dmassadd(theNP->base.mg,bl,level,ALL_VECTORS,np->M,np->t,np->type)) return(1); if (np->LS->PreProcess != NULL) if ((*np->LS->PreProcess)(np->LS,level,ev[0],np->r,np->M, &np->baselevel,&result)) return(1); } for (i=0; i<New; i++) { if (np->conv_mode==1) if (dcopy(theMG,bl,level,ALL_VECTORS,np->s[i],ev[i])) NP_RETURN(1,ewresult->error_code); if (dcopy(theMG,bl,level,ALL_VECTORS,np->t,ev[i])) NP_RETURN(1,ewresult->error_code); if (dmassdot(theMG,bl,level,ALL_VECTORS,np->t,np->E,np->type)) NP_RETURN(1,ewresult->error_code); if (np->LS->Defect!=NULL) if ((*np->LS->Defect)(np->LS,level,ev[i],np->t,np->M, &ewresult->error_code)) NP_RETURN(1,ewresult->error_code); if (np->LS->Residuum!=NULL) if ((*np->LS->Residuum)(np->LS,0,level,ev[i],np->t,np->M, &ewresult->lresult[i])) NP_RETURN(1,ewresult->error_code); if ((*np->LS->Solver)(np->LS,level,ev[i],np->t,np->M, abslimit,reduction, &ewresult->lresult[i])) NP_RETURN(1,ewresult->error_code); if (np->Project != NULL) if (np->Project->Project(np->Project,bl,level, ev[i],&ewresult->error_code) != NUM_OK) NP_RETURN(1,ewresult->error_code); } for (i=0; i<New; i++) { if (ddot(theMG,0,level,ON_SURFACE,ev[i],ev[i],&B[i][i])) NP_RETURN(1,ewresult->error_code); if (dscal(theMG,0,level,ALL_VECTORS,ev[i],1/sqrt(B[i][i])) != NUM_OK) NP_RETURN(1,ewresult->error_code); } for (i=0; i<New; i++) { if (dmatmul (theMG,0,level,ON_SURFACE,np->t,np->M,ev[i]) != NUM_OK) NP_RETURN(1,ewresult->error_code); for (j=0; j<New; j++) if (ddotw(theMG,0,level,ON_SURFACE,np->t,ev[j],np->weight,&A[i][j])) NP_RETURN(1,ewresult->error_code); } for (i=0; i<New; i++) { if (dcopy(theMG,bl,level,ALL_VECTORS,np->t,ev[i])) NP_RETURN(1,ewresult->error_code); if (dmassdot(theMG,bl,level,ALL_VECTORS,np->t,np->E,np->type)) NP_RETURN(1,ewresult->error_code); for (j=0; j<New; j++) if (ddotw(theMG,0,level,ON_SURFACE,np->t,ev[j],np->weight,&B[i][j])) NP_RETURN(1,ewresult->error_code); } /* Special Eigenvalue problem G E_i = lambda E_i */ SmallEWNSolver_Sci(New,A,B,ew_re,ew_im,E); IFDEBUG(np,1) UserWriteF("A\n"); for (i=0; i<New; i++) { for (j=0; j<New; j++) UserWriteF("%8.4f\t",A[i][j]);UserWriteF("\n"); } UserWriteF("B\n"); for (i=0; i<New; i++) { for (j=0; j<New; j++) UserWriteF("%8.4f\t",B[i][j]);UserWriteF("\n"); } UserWriteF("E\n"); for (i=0; i<New; i++) { for (j=0; j<New; j++) UserWriteF("%8.4f\t",E[i][j]);UserWriteF("\n"); } ENDDEBUG for (i=0; i<New; i++) if (AllocVDFromVD(theMG,bl,level,ev[0],&np->e[i])) NP_RETURN(1,ewresult->error_code); for (i=0; i<New; i++) { if (dset(theMG,bl,level,ALL_VECTORS,np->e[i],0.0)) NP_RETURN(1,ewresult->error_code); for (j=0; j<New; j++) if (daxpy(theMG,bl,level,ALL_VECTORS,np->e[i],E[j][i],ev[j]) != NUM_OK) NP_RETURN(1,ewresult->error_code); ddotw(theMG,bl,level,ON_SURFACE,np->e[i],np->e[i],np->weight,&norm); norm=sqrt(norm); dscal(theMG,bl,level,ALL_VECTORS,np->e[i],1.0/norm); } /* sort eigen-values/vectors */ for (i=0; i<New; i++) { tmp_re[i]=ew_re[i]; tmp_im[i]=ew_im[i]; switch (np->order) { case ORDER_REAL_UP : ew[i]=ew_re[i]; break; case ORDER_REAL_DOWN : ew[i]=-ew_re[i]; break; case ORDER_ABS_UP : ew[i]=ew_re[i]*ew_re[i]+ew_im[i]*ew_im[i]; break; case ORDER_ABS_DOWN : ew[i]=-ew_re[i]*ew_re[i]-ew_im[i]*ew_im[i]; break; } table[i] = &ew[i]; } qsort(table, New, sizeof(*table),(int (*)(const void *, const void *))EWCompare); for (i=0; i<New; i++) for (j=0; j<New; j++) if (table[i]==&ew[j]) index[i] = j; for (i=0; i<New; i++) { if (dcopy(theMG,bl,level,ALL_VECTORS,ev[i],np->e[index[i]])) NP_RETURN(1,ewresult->error_code); ew_re[i]=tmp_re[index[i]]; ew_im[i]=tmp_im[index[i]]; } /* shift back eigenvalues */ for (i=0; i<np->ew.nev; i++) ew_re[i]+=shift; /* check convergence */ if (iter>0) { done=1; if (np->conv_mode==0) { /* convergence according to eigenvalues */ for (i=0; i<np->c_n; i++) { if (Round(ew_re[i],np->c_d)!=Round(old_re[i],np->c_d)) done=0; if (Round(ABS(ew_im[i]),np->c_d)!=Round(ABS(old_im[i]),np->c_d)) done=0; } } else { /* convergence according to eigenvectors */ for (i=0; i<New; i++) if (ew_im[i]==0.0) { ddotw(theMG,bl,level,ON_SURFACE,np->s[i],np->e[index[i]],np->weight,&norm); cnorm[i]=1-ABS(norm); if (cnorm[i]>pow(0.1,np->c_d) && i<np->c_n) done=0; } else { ddotw(theMG,bl,level,ON_SURFACE,np->s[i],np->s[i+1],np->weight,&norm_x1x2); ddotw(theMG,bl,level,ON_SURFACE,np->s[i],np->e[index[i]],np->weight,&norm_yx1); ddotw(theMG,bl,level,ON_SURFACE,np->s[i+1],np->e[index[i]],np->weight,&norm_yx2); norm=(norm_yx1*norm_yx1+norm_yx2*norm_yx2-2.0*norm_x1x2*norm_yx1*norm_yx2)/(1.0-norm_x1x2*norm_x1x2); cnorm[i]=1-ABS(norm); if (cnorm[i]>pow(0.1,np->c_d) && i<np->c_n) done=0; ddotw(theMG,bl,level,ON_SURFACE,np->s[i],np->e[index[i+1]],np->weight,&norm_yx1); ddotw(theMG,bl,level,ON_SURFACE,np->s[i+1],np->e[index[i+1]],np->weight,&norm_yx2); i++; norm=(norm_yx1*norm_yx1+norm_yx2*norm_yx2-2.0*norm_x1x2*norm_yx1*norm_yx2)/(1.0-norm_x1x2*norm_x1x2); cnorm[i]=1-ABS(norm); if (cnorm[i]>pow(0.1,np->c_d) && i<np->c_n) done=0; } } } else done=0; for (i=0; i<New; i++) { old_re[i]=ew_re[i]; old_im[i]=ew_im[i]; } /* display */ if (np->display > PCR_NO_DISPLAY) { UserWriteF(formats,iter,shift*np->scale); if (np->conv_mode==0) { /* conv_mode val */ for (i=0; i<np->ew.nev; i++) { ew_re_out=np->scale*ew_re[i]; ew_im_out=np->scale*ew_im[i]; if (i<np->c_n) { UserWriteF(format2,(int)i,ew_re_out,ew_im_out); UserWriteF("\n"); } else { UserWriteF(format3,(int)i,ew_re_out,ew_im_out); UserWriteF("\n"); } } UserWriteF("\n"); } else { /* conv_mode vec */ for (i=0; i<np->ew.nev; i++) { ew_re_out=np->scale*ew_re[i]; ew_im_out=np->scale*ew_im[i]; if (i<np->c_n) { UserWriteF(format2,(int)i,ew_re_out,ew_im_out); UserWriteF(" (%8.6e)\n",cnorm[i]); } else { UserWriteF(format3,(int)i,ew_re_out,ew_im_out); UserWriteF(" [%8.6e]\n",cnorm[i]); } } UserWriteF("\n"); } } /* free VEC_DATADESC's */ for (i=0; i<New; i++) if (FreeVD(theMG,bl,level,np->e[i])) NP_RETURN(1,ewresult->error_code); /* convergence of smallest */ UserWriteF("convergence of smallest\n"); UserWriteF("-----------------------\n"); delta=0.0; for (i=0; i<New; i++) delta=MAX(delta,(ew_re[i]-shift)*(ew_re[i]-shift)+ew_im[i]*ew_im[i]); delta=((ew_re[0]-shift)*(ew_re[0]-shift)+ew_im[0]*ew_im[0])/delta; delta=sqrt(delta); UserWriteF("gamma: %e\n\n",delta); /* calculate shift */ delta=0.0; for (i=0; i<New; i++) delta=MAX(delta,ABS(ew_im[i]));delta=MAX(delta,np->imag_max); shift=ew_re[0]+delta*delta/(ew_re[0]-ew_re[New-1]); delta=0.0; for (i=0; i<New; i++) { delta=ew_re[0]-ew_re[i]; if (delta!=0.0) break;} shift=MIN(shift,ew_re[0]+0.5*delta); shift=MAX(shift,np->shift_min); shift=MIN(shift,np->shift_max); DoLS=0; if (shift!=shift_old) DoLS=1;shift_old=shift; /* postprocess if */ if (done || iter==np->maxiter-1 || DoLS) { if (np->LS->PostProcess!=NULL) if ((*np->LS->PostProcess)(np->LS,level,ev[0],np->r,np->M,&result)) return(1); } /* done? */ if (done) break; } /* print result */ for (i=0; i<np->c_n; i++) { ew_re_out=np->scale*ew_re[i]; ew_im_out=np->scale*ew_im[i]; if (i==0) UserWriteF(formatr1,(int)iter,(int)i,ew_re_out,ew_im_out); else UserWriteF(formatr2,(int)i,ew_re_out,ew_im_out); } UserWriteF("\n"); return (0); }
/* * Imports a CSV file whose elements repeat and generally is composed of only zeroes and ones. */ bool Input::importCSV(char* filename, PatternMatrix& M, unsigned int rowIdx, unsigned int colIdx) { ifstream inFile; bool eof; string currentLine; // currentLine holds the characters of the current line to read unsigned int linelen; int line; eof = false; inFile.open(filename, std::ifstream::in); if (!inFile.good()) { cout << "File does not exists:" << filename << endl; } // Header lines are ignored for (unsigned int i = 0; i < rowIdx; i++) getline(inFile, currentLine); line = 0; linelen = 0; while (!eof) { int i = 0; int dlen = 0; int chars = 0; getline(inFile, currentLine); if (line == 0) linelen = currentLine.length(); else if (linelen != currentLine.length()) { //cout << "Inconsistent line length , stopped importing" << endl; break; } line++; eof = inFile.eof(); const char* processLine = currentLine.c_str(); //Clean string of the ignored columns for (unsigned int k = 0; k < colIdx; ++k) { processLine = strchr(processLine, del); processLine = &processLine[1]; //Skip one character } //Count the binary characters while (processLine[i] != '\0') { if (processLine[i] == '0' || processLine[i] == '1') dlen++; i++; } vector<char> dset(dlen); M.size = dlen; i = 0; chars = 0; while (processLine[i] != '\0') { if (processLine[i] == '0') chars++; if (processLine[i] == '1') { dset[chars] = true; chars++; } i++; } //Bitset is now filled M.push(dset); } inFile.close(); return (0); }
static int vsock_config(config_object_t *config, vsock_options *args) { char value[1024]; int errors = 0; #ifdef _MODULE if (sc_get(config, "fence_virtd/@debug", value, sizeof(value))==0) dset(atoi(value)); #endif if (sc_get(config, "listeners/vsock/@key_file", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for key_file\n", value); args->key_file = strdup(value); } else { args->key_file = strdup(DEFAULT_KEY_FILE); if (!args->key_file) { dbg_printf(1, "Failed to allocate memory\n"); return -1; } } args->hash = DEFAULT_HASH; if (sc_get(config, "listeners/vsock/@hash", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for hash\n", value); if (!strcasecmp(value, "none")) { args->hash = HASH_NONE; } else if (!strcasecmp(value, "sha1")) { args->hash = HASH_SHA1; } else if (!strcasecmp(value, "sha256")) { args->hash = HASH_SHA256; } else if (!strcasecmp(value, "sha512")) { args->hash = HASH_SHA512; } else { dbg_printf(1, "Unsupported hash: %s\n", value); ++errors; } } args->auth = DEFAULT_AUTH; if (sc_get(config, "listeners/vsock/@auth", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for auth\n", value); if (!strcasecmp(value, "none")) { args->hash = AUTH_NONE; } else if (!strcasecmp(value, "sha1")) { args->hash = AUTH_SHA1; } else if (!strcasecmp(value, "sha256")) { args->hash = AUTH_SHA256; } else if (!strcasecmp(value, "sha512")) { args->hash = AUTH_SHA512; } else { dbg_printf(1, "Unsupported auth: %s\n", value); ++errors; } } args->port = DEFAULT_MCAST_PORT; if (sc_get(config, "listeners/vsock/@port", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for port\n", value); args->port = atoi(value); if (args->port <= 0) { dbg_printf(1, "Invalid port: %s\n", value); ++errors; } } return errors; }
static int cpg_virt_init(backend_context_t *c, config_object_t *config) { char value[1024]; struct cpg_info *info = NULL; int ret; ret = cpg_start(PACKAGE_NAME, do_real_work, store_cb, cpg_join_cb, cpg_leave_cb); if (ret < 0) return -1; info = calloc(1, sizeof(*info)); if (!info) return -1; info->magic = MAGIC; info->config = config; #ifdef _MODULE if (sc_get(config, "fence_virtd/@debug", value, sizeof(value)) == 0) dset(atoi(value)); #endif cpg_virt_init_libvirt(info); /* Naming scheme is no longer a top-level config option. * However, we retain it here for configuration compatibility with * versions 0.1.3 and previous. */ if (sc_get(config, "fence_virtd/@name_mode", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for name_mode\n", value); if (!strcasecmp(value, "uuid")) { use_uuid = 1; } else if (!strcasecmp(value, "name")) { use_uuid = 0; } else { dbg_printf(1, "Unsupported name_mode: %s\n", value); } } if (sc_get(config, "backends/cpg/@name_mode", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for name_mode\n", value); if (!strcasecmp(value, "uuid")) { use_uuid = 1; } else if (!strcasecmp(value, "name")) { use_uuid = 0; } else { dbg_printf(1, "Unsupported name_mode: %s\n", value); } } if (info->vp_count < 1) { dbg_printf(1, "[cpg_virt:INIT] Could not connect to any hypervisors\n"); cpg_stop(); free(info); return -1; } pthread_mutex_lock(&local_vm_list_lock); update_local_vms(info); pthread_mutex_unlock(&local_vm_list_lock); *c = (void *) info; cpg_virt_handle = info; return 0; }
static int mcast_config(config_object_t *config, mcast_options *args) { char value[1024]; int errors = 0; #ifdef _MODULE if (sc_get(config, "fence_virtd/@debug", value, sizeof(value))==0) dset(atoi(value)); #endif if (sc_get(config, "listeners/multicast/@key_file", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for key_file\n", value); args->key_file = strdup(value); } else { args->key_file = strdup(DEFAULT_KEY_FILE); if (!args->key_file) { dbg_printf(1, "Failed to allocate memory\n"); return -1; } } args->hash = DEFAULT_HASH; if (sc_get(config, "listeners/multicast/@hash", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for hash\n", value); if (!strcasecmp(value, "none")) { args->hash = HASH_NONE; } else if (!strcasecmp(value, "sha1")) { args->hash = HASH_SHA1; } else if (!strcasecmp(value, "sha256")) { args->hash = HASH_SHA256; } else if (!strcasecmp(value, "sha512")) { args->hash = HASH_SHA512; } else { dbg_printf(1, "Unsupported hash: %s\n", value); ++errors; } } args->auth = DEFAULT_AUTH; if (sc_get(config, "listeners/multicast/@auth", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for auth\n", value); if (!strcasecmp(value, "none")) { args->auth = AUTH_NONE; } else if (!strcasecmp(value, "sha1")) { args->auth = AUTH_SHA1; } else if (!strcasecmp(value, "sha256")) { args->auth = AUTH_SHA256; } else if (!strcasecmp(value, "sha512")) { args->auth = AUTH_SHA512; } else { dbg_printf(1, "Unsupported auth: %s\n", value); ++errors; } } args->family = PF_INET; if (sc_get(config, "listeners/multicast/@family", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for family\n", value); if (!strcasecmp(value, "ipv4")) { args->family = PF_INET; } else if (!strcasecmp(value, "ipv6")) { args->family = PF_INET6; } else { dbg_printf(1, "Unsupported family: %s\n", value); ++errors; } } if (sc_get(config, "listeners/multicast/@address", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for address\n", value); args->addr = strdup(value); } else { if (args->family == PF_INET) { args->addr = strdup(IPV4_MCAST_DEFAULT); } else { args->addr = strdup(IPV6_MCAST_DEFAULT); } } if (!args->addr) { return -1; } args->port = DEFAULT_MCAST_PORT; if (sc_get(config, "listeners/multicast/@port", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for port\n", value); args->port = atoi(value); if (args->port <= 0) { dbg_printf(1, "Invalid port: %s\n", value); ++errors; } } args->ifindex = 0; if (sc_get(config, "listeners/multicast/@interface", value, sizeof(value)-1) == 0) { dbg_printf(1, "Got %s for interface\n", value); args->ifindex = if_nametoindex(value); if (args->ifindex < 0) { dbg_printf(1, "Invalid interface: %s\n", value); ++errors; } } return errors; }
int main(int argc, char **argv) { char val[4096]; char listener_name[80]; char backend_name[80]; const char *config_file = DEFAULT_CONFIG_FILE; config_object_t *config = NULL; map_object_t *map = NULL; const listener_plugin_t *lp; const backend_plugin_t *p; listener_context_t listener_ctx = NULL; backend_context_t backend_ctx = NULL; int debug_set = 0, foreground = 0, wait_for_init = 0; int opt, configure = 0; config = sc_init(); map = map_init(); if (!config || !map) { perror("malloc"); return -1; } while ((opt = getopt(argc, argv, "Ff:d:cwlh")) != EOF) { switch(opt) { case 'F': printf("Background mode disabled\n"); foreground = 1; break; case 'f': printf("Using %s\n", optarg); config_file = optarg; break; case 'd': debug_set = atoi(optarg); break; case 'c': configure = 1; break; case 'w': wait_for_init = 1; break; case 'l': plugin_dump(); return 0; case 'h': case '?': usage(); return 0; default: return -1; } } if (configure) { return do_configure(config, config_file); } if (sc_parse(config, config_file) != 0) { printf("Failed to parse %s\n", config_file); return -1; } if (debug_set) { snprintf(val, sizeof(val), "%d", debug_set); sc_set(config, "fence_virtd/@debug", val); } else { if (sc_get(config, "fence_virtd/@debug", val, sizeof(val))==0) debug_set = atoi(val); } dset(debug_set); if (!foreground) { if (sc_get(config, "fence_virtd/@foreground", val, sizeof(val)) == 0) foreground = atoi(val); } if (!wait_for_init) { if (sc_get(config, "fence_virtd/@wait_for_init", val, sizeof(val)) == 0) wait_for_init = atoi(val); if (!wait_for_init) { /* XXX compat */ if (sc_get(config, "fence_virtd/@wait_for_backend", val, sizeof(val)) == 0) wait_for_init = atoi(val); } } if (dget() > 3) sc_dump(config, stdout); if (sc_get(config, "fence_virtd/@backend", backend_name, sizeof(backend_name))) { printf("Failed to determine backend.\n"); printf("%s\n", val); return -1; } dbg_printf(1, "Backend plugin: %s\n", backend_name); if (sc_get(config, "fence_virtd/@listener", listener_name, sizeof(listener_name))) { printf("Failed to determine backend.\n"); printf("%s\n", val); return -1; } dbg_printf(1, "Listener plugin: %s\n", listener_name); #ifdef _MODULE if (sc_get(config, "fence_virtd/@module_path", val, sizeof(val))) { #ifdef MODULE_PATH snprintf(val, sizeof(val), MODULE_PATH); #else printf("Failed to determine module path.\n"); return -1; #endif } dbg_printf(1, "Searching %s for plugins...\n", val); opt = plugin_search(val); if (opt > 0) { dbg_printf(1, "%d plugins found\n", opt); } else { printf("No plugins found\n"); return 1; } #endif if (dget() > 3) plugin_dump(); lp = plugin_find_listener(listener_name); if (!lp) { printf("Could not find listener \"%s\"\n", listener_name); return 1; } p = plugin_find_backend(backend_name); if (!p) { printf("Could not find backend \"%s\"\n", backend_name); return 1; } daemon_init(basename(argv[0]), foreground); signal(SIGINT, exit_handler); signal(SIGTERM, exit_handler); signal(SIGQUIT, exit_handler); syslog(LOG_NOTICE, "fence_virtd starting. Listener: %s Backend: %s", backend_name, listener_name); while (p->init(&backend_ctx, config) < 0) { if (!wait_for_init) { if (foreground) { printf("Backend plugin %s failed to initialize\n", backend_name); } syslog(LOG_ERR, "Backend plugin %s failed to initialize\n", backend_name); return 1; } sleep(5); } if (map_load(map, config) < 0) { syslog(LOG_WARNING, "Failed to load static maps\n"); } /* only client we have now is mcast (fence_xvm behavior) */ while (lp->init(&listener_ctx, p->callbacks, config, map, backend_ctx) != 0) { if (!wait_for_init) { if (foreground) { printf("Listener plugin %s failed to initialize\n", listener_name); } syslog(LOG_ERR, "Listener plugin %s failed to initialize\n", listener_name); return 1; } sleep(5); } while (run && lp->dispatch(listener_ctx, NULL) >= 0); syslog(LOG_NOTICE, "fence_virtd shutting down"); map_release(map); sc_release(config); lp->cleanup(listener_ctx); p->cleanup(backend_ctx); daemon_cleanup(); return 0; }
static INT AMGSolver (NP_LINEAR_SOLVER *theNP, INT level, VECDATA_DESC *x, VECDATA_DESC *b, MATDATA_DESC *A, VEC_SCALAR abslimit, VEC_SCALAR reduction, LRESULT *lresult) { NP_AMG *theAMGC; VEC_SCALAR defect2reach; INT rv,i,bl,PrintID; char text[DISPLAY_WIDTH+4]; VEC_SCALAR Factor_One; MULTIGRID *theMG; GRID *theGrid; INT converged=0; int xcomp,bcomp; VECTOR *theVector; int k; INT nComp_x,nComp_b; int blocksize; double ti; int ii; #ifdef ModelP double clock_start; #else clock_t clock_start; #endif /* prepare solving */ theAMGC = (NP_AMG *) theNP; theMG = theAMGC->ls.base.mg; theGrid = GRID_ON_LEVEL(theMG,level); theAMGC->sc.red_factor=reduction[0]; theAMGC->sc.dnorm_min=abslimit[0]; if (theAMGC->AMG_Build_failed) { dset(NP_MG(theNP),level,level,ALL_VECTORS,x,0.0); return (0); } bl = 0; for (i=0; i<MAX_VEC_COMP; i++) Factor_One[i] = 1.0; /* allocate correction */ if (AllocVDFromVD(theNP->base.mg,0,level,x,&theAMGC->c)) { lresult->error_code = __LINE__; return(1); } /* print defect */ CenterInPattern(text,DISPLAY_WIDTH,ENVITEM_NAME(theAMGC),'*',"\n"); if (PreparePCR(x,theAMGC->display,text,&PrintID)) { lresult->error_code = __LINE__; return(1); } for (i=0; i<VD_NCOMP(x); i++) lresult->first_defect[i] = lresult->last_defect[i]; if (sc_mul_check(defect2reach,lresult->first_defect,reduction,b)) { lresult->error_code = __LINE__; return(1); } if (DoPCR(PrintID,lresult->first_defect,PCR_CRATE)) { lresult->error_code = __LINE__; return(1); } if (sc_cmp(lresult->first_defect,abslimit,b)) lresult->converged = 1; else lresult->converged = 0; CSTART(); ti=0; ii=0; /* fill values in x,b */ xcomp = VD_ncmp_cmpptr_of_otype(theAMGC->c,NODEVEC,&nComp_x)[0]; bcomp = VD_ncmp_cmpptr_of_otype(b,NODEVEC,&nComp_b)[0]; blocksize = nComp_x; if (blocksize==0) goto exit; if (nComp_b!=blocksize) goto exit; for (theVector=FIRSTVECTOR(theGrid); theVector!= NULL; theVector=SUCCVC(theVector)) { i = VINDEX(theVector); for (k=0; k<blocksize; k++) { AMG_VECTOR_ENTRY(theAMGC->b,i*blocksize+k,0)=VVALUE(theVector,bcomp+k); } } #ifdef ModelP /* only master solves */ if (me == master) { #endif AMG_dset(theAMGC->x,0.0); if ((rv=AMG_Solve(theAMGC->x,theAMGC->b))<0) { lresult->error_code = __LINE__; lresult->converged = 0; goto exit; } lresult->converged = 1; lresult->number_of_linear_iterations = rv; /* write back solution values */ for (theVector=FIRSTVECTOR(theGrid); theVector!= NULL; theVector=SUCCVC(theVector)) { i = VINDEX(theVector); for (k=0; k<blocksize; k++) VVALUE(theVector,xcomp+k)=AMG_VECTOR_ENTRY(theAMGC->x,i*blocksize+k,0); } if (dmatmul_minus(theNP->base.mg,0,level,ON_SURFACE,b,A,theAMGC->c) != NUM_OK) { lresult->error_code = __LINE__; return(1); } if (daxpyx(theAMGC->ls.base.mg,0,level, ON_SURFACE,x,Factor_One,theAMGC->c) != NUM_OK) { lresult->error_code = __LINE__; return(1); } #ifdef ModelP } #endif if (AMGSolverResiduum(theNP,bl,level,x,b,A,lresult)) return(1); if (DoPCR(PrintID, lresult->last_defect,PCR_CRATE)) { lresult->error_code = __LINE__; return (1); } if (DoPCR(PrintID,lresult->last_defect,PCR_AVERAGE)) { lresult->error_code = __LINE__; return (1); } FreeVD(theNP->base.mg,0,level,theAMGC->c); if (PostPCR(PrintID,NULL)) { lresult->error_code = __LINE__; return (1); } CSTOP(ti,ii); if (theAMGC->sc.verbose>0) { if (lresult->number_of_linear_iterations != 0) UserWriteF("AMG : L=%2d N=%2d TSOLVE=%10.4g TIT=%10.4g\n",level, lresult->number_of_linear_iterations,ti, ti/lresult->number_of_linear_iterations); else UserWriteF("AMG : L=%2d N=%2d TSOLVE=%10.4g\n",level, lresult->number_of_linear_iterations,ti); } return (0); exit: return(1); }
static void test_accuracy(int argc, char **argv){ double displacex=0.01; double displacey=0.05; double scale=1.01;/*.414065; */ int wrap=0; double D=30; double D2=32; int save=1; if(argc>1){ scale=strtod(argv[1], 0); } if(argc>2){ displacex=strtod(argv[2], 0); } if(argc>3){ displacey=strtod(argv[3], 0); } if(argc>4){ wrap=strtol(argv[4], 0, 10); } if(argc>5){ D=strtod(argv[5], 0); } if(argc>6){ D2=strtod(argv[6], 0); } if(argc>7){ save=strtol(argv[7], 0, 10); } double dx=1/64.; double dsa=0.5; map_t *screen=mapnew(D2/dx, D2/dx, dx, dx, 0); dset((dmat*)screen, 1); for(long iy=0; iy<screen->ny; iy++){ for(long ix=0; ix<screen->nx; ix++){ screen->p[ix+iy*screen->nx]=sin((double)ix/screen->nx*2*M_PI)*sin((double)iy/screen->ny*2*M_PI); } } /*loc for the map */ loc_t *locin=mksqloc(screen->nx,screen->ny,dx,dx,screen->ox,screen->oy); //pts_t *pts=realloc(mkannloc(D, 0, 1./2.,0), sizeof(pts_t)); pts_t *pts=realloc(mksqloc_auto(D/dsa, D/dsa, dsa, dsa), sizeof(pts_t)); pts->dx=dx; pts->dy=dx; pts->nx=dsa/dx; pts->ny=pts->nx; loc_t *loc=pts2loc(pts); loc_create_map(locin); loc_create_stat(loc); loc_create_map(loc); locstat_t *locstat=loc->stat; map_t *screen2=mapnew2(locin->map); dset((dmat*)screen2, NAN); loc_embed(screen2, locin, screen->p); double *phi_pts, *phi_loc, *phi_stat; double *phi_loc2loc, *phi_h, *phi_cub, *phi_cub2, *phi_cubh; double cubic=0.3; int ii; info("displacex=%g, displacey=%g, scale=%g, wrap=%d\n", displacex, displacey,scale,wrap); double diff1, diff2,diff3,diff14,diff15; diff1=0; diff2=0; diff3=0; diff14=0; diff15=0; phi_pts=calloc(loc->nloc, sizeof(double)); phi_loc=calloc(loc->nloc, sizeof(double)); phi_stat=calloc(loc->nloc, sizeof(double)); phi_loc2loc=calloc(loc->nloc, sizeof(double)); map_t *map1=mapnew2(loc->map); prop_grid_map(screen, map1, -2, displacex, displacey, scale, wrap, 0,0); tic; prop_grid_map(screen, map1, 1, displacex, displacey, scale, wrap, 0,0); toc("map\t\t"); prop_grid_pts(screen, pts, phi_pts, -2, displacex, displacey, scale, wrap, 0,0); tic; prop_grid_pts(screen, pts, phi_pts, 1, displacex, displacey, scale, wrap, 0,0); toc("pts\t\t"); prop_grid_stat(screen, locstat, phi_stat, -2,displacex, displacey, scale, wrap, 0,0); tic; prop_grid_stat(screen, locstat, phi_stat , 1, displacex, displacey, scale, wrap, 0,0); toc("stat\t");tic; prop_grid(screen, loc, phi_loc, -2,displacex, displacey, scale, wrap, 0,0); tic; prop_grid(screen, loc, phi_loc, 1,displacex, displacey, scale, wrap, 0,0); toc("loc\t\t"); prop_nongrid(locin, screen->p,loc, phi_loc2loc, -2,displacex, displacey, scale,0,0); toc("nongrid\t"); tic; prop_nongrid(locin, screen->p,loc, phi_loc2loc, 1,displacex, displacey, scale,0,0); toc("nongrid\t"); phi_h=calloc(loc->nloc,sizeof(double)); tic; dsp *hfor=mkh(locin, loc, displacex, displacey, scale); toc("mkh\t\t\t"); dspmulvec(phi_h,hfor, screen->p, 'n', -2); tic; dspmulvec(phi_h,hfor, screen->p, 'n', 1); toc("mul h\t\t"); phi_cub=calloc(loc->nloc,sizeof(double)); phi_cub2=calloc(loc->nloc,sizeof(double)); double *phi_cub3=calloc(loc->nloc,sizeof(double)); double *phi_cub4=calloc(loc->nloc,sizeof(double)); phi_cubh=calloc(loc->nloc, sizeof(double)); prop_nongrid_cubic(locin,screen->p,loc,phi_cub,-2, displacex, displacey, scale, cubic,0,0); tic; prop_nongrid_cubic(locin,screen->p,loc,phi_cub,1, displacex, displacey, scale, cubic,0,0); toc("nongrid, cubic\t"); prop_grid_cubic(screen, loc, phi_cub2, -2,displacex, displacey, scale, cubic, 0,0); tic; prop_grid_cubic(screen, loc, phi_cub2, 1,displacex, displacey, scale, cubic, 0,0); toc("grid, cubic\t"); prop_grid_cubic(screen2, loc,phi_cub3, -2,displacex, displacey, scale, cubic, 0,0); tic; prop_grid_cubic(screen2, loc,phi_cub3, 1,displacex, displacey, scale, cubic, 0,0); toc("grid2, cubic\t"); prop_grid_stat_cubic(screen, locstat,phi_cub4, -2,displacex, displacey, scale, cubic, 0,0); tic; prop_grid_stat_cubic(screen, locstat,phi_cub4, 1,displacex, displacey, scale, cubic, 0,0); toc("grid 2stat, cubic\t"); dsp *hforcubic; tic; hforcubic=mkh_cubic(locin, loc, displacex, displacey, scale, cubic); toc("mkh cubic \t\t"); dspmulvec(phi_cubh, hforcubic,screen->p,'n',-2); tic; dspmulvec(phi_cubh, hforcubic,screen->p,'n',1); toc("cubic mul h\t\t"); double diffc12=0,diff45=0,diff46=0,diff47=0; for(ii=0; ii<loc->nloc; ii++){ diff1+=fabs(phi_loc[ii]-phi_pts[ii]); diff2+=fabs(phi_stat[ii]-phi_loc[ii]); diff3+=fabs(phi_stat[ii]-phi_pts[ii]); diff14+=fabs(phi_loc2loc[ii]-phi_pts[ii]); diff15+=fabs(phi_h[ii]-phi_pts[ii]); diff45+=fabs(phi_loc2loc[ii]-phi_h[ii]); diffc12+=fabs(phi_cub[ii]-phi_cubh[ii]); diff46+=fabs(phi_cub[ii]-phi_cub2[ii]); diff47+=fabs(phi_cub[ii]-phi_cub3[ii]); } info2("(pts-loc)=\t%g\n(loc-stat)=\t%g\n(stat-pts)=\t%g\n" "(loc2loc-pts)=\t%g\n(h-pts)=\t%g\n" "(loc2loc-h)=\t%g\n" "(cub:h-loc2loc)=\t%g\n" "(cub:map2loc-loc2loc)=\t%g\n" "(cub:locmap2loc-loc2loc=\t%g\n" ,diff1, diff2,diff3,diff14,diff15,diff45,diffc12, diff46, diff47); // exit(0); if(!save) return; mapwrite(screen2,"accphi_screen2"); mapwrite(screen,"accphi_screen"); locwrite((loc_t*)pts,"accphi_pts"); locwrite(loc,"accphi_loc"); locwrite(locin, "accphi_locin"); loc_create_map_npad(locin, 0, 0, 0); mapwrite(locin->map, "accphi_locin_map"); mapwrite(loc->map, "accphi_loc_map"); mapwrite(map1, "accphi_map2map.bin"); writedbl(phi_pts,loc->nloc,1,"accphi_pts1.bin"); writedbl(phi_loc,loc->nloc,1,"accphi_loc0.bin"); writedbl(phi_stat,loc->nloc,1,"accphi_stat.bin"); writedbl(phi_loc2loc,loc->nloc,1,"accphi_loc2loc.bin"); writedbl(phi_h,loc->nloc,1,"accphi_loc2h.bin"); writedbl(phi_cub,loc->nloc,1,"accphi_cub_loc2loc.bin"); writedbl(phi_cub2,loc->nloc,1,"accphi_cub_map2loc.bin"); writedbl(phi_cub3,loc->nloc,1,"accphi_cub_locmap2loc.bin"); writedbl(phi_cub4,loc->nloc,1,"accphi_cub_locmap2stat.bin"); writedbl(phi_cubh,loc->nloc,1,"accphi_cub_loc2h.bin"); info("saved\n"); writedbl(phi_pts,loc->nloc,1,"accphi_pts.bin"); writedbl(phi_cub,loc->nloc,1,"accphi_cub.bin"); writebin(hfor, "accphi_hfor"); writebin(hforcubic, "accphi_cub_hfor"); dspfree(hfor); dspfree(hforcubic); free(phi_loc); free(phi_stat); free(phi_loc2loc); free(phi_pts); free(phi_h); free(phi_cub); free(phi_cubh); cellfree(screen); locfree(locin); }
INT NS_DIM_PREFIX CheckNP (MULTIGRID *theMG, INT argc, char **argv) { MATDATA_DESC *A; VECDATA_DESC *x,*y; INT i,level,nerr; char value[VALUELEN]; VEC_SCALAR damp; DOUBLE nrm,diff; if (ReadArgvChar("A",value,argc,argv) == 0) { A = GetMatDataDescByName(theMG,value); if (A == NULL) { UserWriteF("ERROR: no matrix %s in npckeck\n",value); return(1); } if (ReadArgvOption("S",argc,argv)) { for (level=theMG->bottomLevel; level<=TOPLEVEL(theMG); level++) if (CheckSymmetryOfMatrix(GRID_ON_LEVEL(theMG,level),A)) UserWriteF("matrix %s not symmetric on level %d\n", ENVITEM_NAME(A),level); return(0); } if (ReadArgvOption("G",argc,argv)) { if (ReadArgvChar("x",value,argc,argv)) { UserWriteF("ERROR: no vector in npckeck\n"); return(1); } x = GetVecDataDescByName(theMG,value); if (x == NULL) { UserWriteF("ERROR: no vector %s in npckeck\n",value); return(1); } level = CURRENTLEVEL(theMG); if (level == BOTTOMLEVEL(theMG)) { UserWriteF("ERROR: no GalerkinCheck," "level %d is bottomlevel\n",level); return(1); } if (AllocVDFromVD(theMG,level-1,level,x,&y)) return(1); dmatset(theMG,level-1,level-1,ALL_VECTORS,A,0.0); dset(theMG,level,level,ALL_VECTORS,x,0.0); dset(theMG,level-1,level,ALL_VECTORS,y,0.0); AssembleGalerkinByMatrix(GRID_ON_LEVEL(theMG,level),A,0); for (i=0; i<VD_NCOMP(x); i++) damp[i] = 1.0; InterpolateCorrectionByMatrix(GRID_ON_LEVEL(theMG,level),x,x,damp); if (dmatmul(theMG,level,level,ALL_VECTORS,y,A,x) != NUM_OK) return(1); RestrictByMatrix(GRID_ON_LEVEL(theMG,level),y,y,damp); IFDEBUG(np,1) UserWriteF("x %d\n",level-1); PrintVector(GRID_ON_LEVEL(theMG,level-1),x,3,3); UserWriteF("x %d\n",level); PrintVector(GRID_ON_LEVEL(theMG,level),x,3,3); UserWriteF("y %d\n",level); PrintVector(GRID_ON_LEVEL(theMG,level),y,3,3); UserWriteF("y %d\n",level-1); PrintVector(GRID_ON_LEVEL(theMG,level-1),y,3,3); ENDDEBUG if (dmatmul_minus(theMG,level-1,level-1,ALL_VECTORS,y,A,x)!=NUM_OK) return(1); IFDEBUG(np,1) UserWriteF("y %d\n",level-1); PrintVector(GRID_ON_LEVEL(theMG,level-1),y,3,3); ENDDEBUG dnrm2(theMG,level-1,level-1,ALL_VECTORS,x,&nrm); dnrm2(theMG,level-1,level-1,ALL_VECTORS,y,&diff); UserWriteF("Galerkin test: nrm(x) = %f nrm(Ax-RAPx) = %f\n", nrm,diff); return(0); } }
int main(int argc, char **argv) { fence_virt_args_t args; const char *my_options; int ret = 0; args_init(&args); if (!strcmp(basename(argv[0]), "fence_xvm")) { my_options = "di:a:p:r:C:c:k:M:H:uo:t:?hVw:"; args.mode = MODE_MULTICAST; } else { my_options = "dD:P:A:p:M:H:o:t:?hVT:C:c:k:w:"; args.mode = MODE_SERIAL; } if (argc == 1) { args_get_stdin(my_options, &args); } else { args_get_getopt(argc, argv, my_options, &args); } if (args.flags & F_HELP) { args_usage(argv[0], my_options, 0); printf("With no command line argument, arguments are " "read from standard input.\n"); printf("Arguments read from standard input take " "the form of:\n\n"); printf(" arg1=value1\n"); printf(" arg2=value2\n\n"); args_usage(argv[0], my_options, 1); exit(0); } if (args.flags & F_VERSION) { printf("%s %s\n", basename(argv[0]), XVM_VERSION); #ifdef FENCE_RELEASE_NAME printf("fence release %s\n", FENCE_RELEASE_NAME); #endif exit(0); } openlog(basename(argv[0]), LOG_NDELAY | LOG_PID, LOG_DAEMON); args_finalize(&args); dset(args.debug); if (args.debug > 0) args_print(&args); /* Additional validation here */ if (!args.domain && (args.op != FENCE_DEVSTATUS && args.op != FENCE_HOSTLIST && args.op != FENCE_METADATA)) { printf("No domain specified!\n"); syslog(LOG_NOTICE, "No domain specified"); args.flags |= F_ERR; } if (args.net.ipaddr) { args.mode = MODE_TCP; } if (args.flags & F_ERR) { args_usage(argv[0], my_options, (argc == 1)); exit(1); } if (args.op == FENCE_METADATA) { args_metadata(argv[0], my_options); return 0; } if (args.delay > 0 && args.op != FENCE_STATUS && args.op != FENCE_DEVSTATUS && args.op != FENCE_HOSTLIST) sleep(args.delay); switch(args.mode) { case MODE_MULTICAST: ret = mcast_fence_virt(&args); break; case MODE_SERIAL: ret = serial_fence_virt(&args); break; case MODE_TCP: ret = tcp_fence_virt(&args); break; default: ret = 1; goto out; } switch(ret) { case RESP_OFF: if (args.op == FENCE_STATUS) printf("Status: OFF\n"); else if (args.domain) syslog(LOG_NOTICE, "Domain \"%s\" is OFF", args.domain); break; case 0: if (args.op == FENCE_STATUS) printf("Status: ON\n"); else if (args.domain) syslog(LOG_NOTICE, "Domain \"%s\" is ON", args.domain); break; case RESP_FAIL: if (args.domain) { syslog(LOG_NOTICE, "Fence operation failed for domain \"%s\"", args.domain); } else syslog(LOG_NOTICE, "Fence operation failed"); printf("Operation failed\n"); break; case RESP_PERM: if (args.domain) { syslog(LOG_NOTICE, "Permission denied for Fence operation for domain \"%s\"", args.domain); } else syslog(LOG_NOTICE, "Permission denied for fence operation"); printf("Permission denied\n"); break; default: if (args.domain) { syslog(LOG_NOTICE, "Unknown response (%d) for domain \"%s\"", ret, args.domain); } else syslog(LOG_NOTICE, "Unknown response (%d)", ret); printf("Unknown response (%d)\n", ret); break; } out: closelog(); return ret; }