int fab(int i) { if (i == 0) return 0 else if (i == 1) return 1; return fab(i-1) + fab(i-2); }
int main() { int n; scanf("%d",&n); printf("%lld\n",fab(n)); return 0; }
void MappedLevelFluxRegister::poutFineRegisters() const { for (DataIterator dit = m_fineFlux.dataIterator(); dit.ok(); ++dit) { pout() << "dumping fine registers" << endl; const FArrayBox& fab = m_fineFlux[dit()]; const Box& box = fab.box(); for (BoxIterator bit(box); bit.ok(); ++bit) { if (Abs(fab(bit(), 0)) > 0.0) { pout() << bit() << " "; for (int ivar = 0; ivar < fab.nComp(); ivar++) { pout() << fab(bit(), ivar) << " "; } pout() << endl; } } } }
int main() { for (i = 0; i < PRINT_NUM; i++) { printf("%d ", fab(i)); } printf("\n"); return 0; }
float fun(int m,int n) { float x1=m,x2=n,tmp=(x1*fang(x2)-x2*fang(x1))/(fang(x2)-fang(x1)); while(fab(fang(tmp))>1e-4) { if(fang(tmp)*fang(x1)>0)x1=tmp; else if(fang(tmp)*fang(x2)>0)x2=tmp; tmp=(x1*fang(x2)-x2*fang(x1))/(fang(x2)-fang(x1)); } return tmp; }
int main(){ int sortNum[5] = {5,4,7,2,0}; quick(0,4, sortNum); SORT[0] = sortNum[0]; SORT[1] = sortNum[1]; SORT[2] = sortNum[2]; SORT[3] = sortNum[3]; SORT[4] = sortNum[4]; ANS = fab(20); return 0; }
int main() { int i, j, k, n, m, p, q, t, K, a, b; scanf("%d", &t); for (i = 0; i < t; i++) { scanf("%d%d%d", &m, &n, &K); q = 0; for (j = 1; j <= m; j++) { for (k = 1; k <= n; k++) { scanf("%d", &p); if (p != 0) { peanut[q].num = p; peanut[q].x = j; peanut[q].y = k; q++; } } } qsort(peanut, q, sizeof(peanut[0]), cmp); p = 0; j = 0; k = 0; a = 0; b = peanut[0].y; while (j + fab(peanut[k].x, a) + fab(peanut[k].y, b) + peanut[k].x + 1 <= K) { j += fab(peanut[k].x, a) + fab(peanut[k].y, b) + 1; a = peanut[k].x; b = peanut[k].y; p += peanut[k].num; k++; } printf("%d\n", p); } return 0; }
int copyTest() { IntVect ivlo = IntVect::Zero; IntVect ivhi = 7*IntVect::Unit; Box box(ivlo, ivhi); int ncomp = 5; FArrayBox fab(box, ncomp); Vector<Real> exactVal(ncomp); for (int i = 0; i < ncomp; i++) { exactVal[i] = Real(i) + 1.2345; fab.setVal(exactVal[i],i); } int dstvar = 3; int srcvar = 2; //now copy from one comp to another Interval srcI(srcvar, srcvar); Interval dstI(dstvar, dstvar); fab.copy( fab.box(), dstI, fab.box(), fab, srcI ); int icode = 0; Real tol = 1.0e-10; for (BoxIterator bit(box); bit.ok(); ++bit) { Real fabVal = fab(bit(), dstvar); if (Abs(fabVal-exactVal[srcvar]) > tol) { icode = 1; return(icode); } } return(icode); }
int checkIrregFabCopy(const Box& a_domain) { int eekflag = 0; int nvar = 1; Interval interv(0,0); int nghost= 0; IntVect ivgh= IntVect::Zero; Real tolerance = PolyGeom::getTolerance(); const EBIndexSpace* const ebisPtr = Chombo_EBIS::instance(); int numlevels = ebisPtr->numLevels(); Box levelDomain = a_domain; for (int ilev = 0; ilev < numlevels-1; ilev++) { DisjointBoxLayout dblOne, dblTwo; int maxsizeOne = 4; int maxsizeTwo = 2; makeLayout(dblOne, levelDomain, maxsizeOne); makeLayout(dblTwo, levelDomain, maxsizeTwo); EBISLayout ebislOne, ebislTwo; makeEBISL(ebislOne, dblOne, levelDomain, nghost); makeEBISL(ebislTwo, dblTwo, levelDomain, nghost); LayoutData<IntVectSet> ldIVSOne(dblOne); LayoutData<IntVectSet> ldIVSTwo(dblTwo); for (DataIterator dit = dblOne.dataIterator(); dit.ok(); ++dit) ldIVSOne[dit()] = IntVectSet(dblOne.get(dit())); for (DataIterator dit = dblTwo.dataIterator(); dit.ok(); ++dit) ldIVSTwo[dit()] = IntVectSet(dblTwo.get(dit())); BaseIVFactory<Real> factOne(ebislOne, ldIVSOne); BaseIVFactory<Real> factTwo(ebislTwo, ldIVSTwo); LevelData<BaseIVFAB<Real> > dataOne(dblOne, nvar, ivgh, factOne); LevelData<BaseIVFAB<Real> > dataTwo(dblTwo, nvar, ivgh, factTwo); for (DataIterator dit = dblOne.dataIterator(); dit.ok(); ++dit) dataOne[dit()].setVal(1); for (DataIterator dit = dblTwo.dataIterator(); dit.ok(); ++dit) dataTwo[dit()].setVal(2); //copy dataone into datatwo. then all datatwo should hold are ones dataOne.copyTo(interv, dataTwo, interv); Real rightVal = 1.0; for (DataIterator dit = dblTwo.dataIterator(); dit.ok(); ++dit) { const EBISBox& ebisBox = ebislTwo[dit()]; const IntVectSet& ivs = ldIVSTwo[dit()]; const BaseIVFAB<Real>& fab = dataTwo[dit()]; for (VoFIterator vofit(ivs, ebisBox.getEBGraph()); vofit.ok(); ++vofit) { Real thisVal = fab(vofit(), 0); if (Abs(thisVal - rightVal) > tolerance) { eekflag = 3; return eekflag; } } } levelDomain.coarsen(2); } return eekflag; }
int fab(int num){ if(num == 1) return 1; return fab(num-1) + num; }
int test() { #ifdef CH_USE_HDF5 int error; HDF5Handle testFile; CH_assert(!testFile.isOpen()); error = testFile.open("data.h5", HDF5Handle::CREATE); if (error != 0) { if ( verbose ) pout() << indent2 << "File creation failed "<<error<<endl; return error; } CH_assert(testFile.isOpen()); Box domain(IntVect::Zero, 20*IntVect::Unit); DisjointBoxLayout plan1, plan2; { IntVectSet tags; IntVect center = 10*IntVect::Unit; setCircleTags(tags, 6, 1, center); //circle/sphere buildDisjointBoxLayout(plan1, tags, domain); tags.makeEmpty(); setCircleTags(tags, 5, 2, center); buildDisjointBoxLayout(plan2, tags, domain); } if ( verbose ) { pout() << "plan1: " << procID() << "...." << plan1 << endl; pout() << "plan2: " << procID() << "...." << plan2 << endl; } //test LayoutData<Real> specialization LayoutData<Real> specialReal(plan1); LayoutData<Moment> vlPlan(plan1); LevelData<BaseFab<int> > level1(plan1, 3, IntVect::Unit); LevelData<BaseFab<int> > level2; level2.define(level1); level2.define(plan2, 1); for (DataIterator i(level2.dataIterator()); i.ok(); ++i) { level2[i()].setVal(2); } level1.apply(values::setVal1); level2.apply(values::setVal2); HDF5HeaderData set1; Real dx=0.004; Box b1(IntVect(D_DECL6(1,2,1,1,2,1)), IntVect(D_DECL6(4,4,4,4,4,4))); Box b2(IntVect(D_DECL6(5,2,1,5,2,1)), IntVect(D_DECL6(12,4,4,12,4,4))); int currentStep = 2332; set1.m_string["name"] = "set1"; set1.m_real["dx"] = dx; set1.m_int["currentStep"] = currentStep; set1.m_intvect["some intvect or other"] = b1.smallEnd(); set1.m_box["b1"] = b1; set1.m_box["b2"] = b2; testFile.setGroupToLevel(1); error = write(testFile, plan1); if (error != 0) { if ( verbose ) pout() << indent2 << "box write failed "<<error<<endl; return error; } error = write(testFile, level1, "level1 state vector"); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 1 write failed "<<error<<endl; return error; } testFile.setGroupToLevel(2); error = write(testFile, plan2); if (error != 0) { if ( verbose ) pout() << indent2 << "box2 write failed "<<error<<endl; return error; } error = write(testFile, level2, "level2 state vector"); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl; return error; } LevelData<FArrayBox> state(plan2, 3); state.apply(values::setVal3); testFile.setGroupToLevel(0); set1.writeToFile(testFile); error = write(testFile, plan2); if (error != 0) { if ( verbose ) pout() << indent2 << "box2 write failed "<<error<<endl; return error; } testFile.setGroup("/"); error = writeLevel(testFile, 0, state, 2, 1, 0.001, b2, 2); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData 2 write failed "<<error<<endl; return error; } set1.writeToFile(testFile); set1.writeToFile(testFile); testFile.close(); CH_assert(!testFile.isOpen()); // test the utility functions ReadUGHDF5 and WriteUGHDF5 WriteUGHDF5("UGIO.hdf5", plan2, state, domain); ReadUGHDF5("UGIO.hdf5", plan2, state, domain); //======================================================================== // // now, read this data back in // //======================================================================== BoxLayoutData<BaseFab<int> > readlevel1, readlevel2; error = testFile.open("data.h5", HDF5Handle::OPEN_RDONLY); if (error != 0) { if ( verbose ) pout() << indent2 << "File open failed "<<error<<endl; return error; } testFile.setGroupToLevel(2); Vector<Box> boxes; error = read(testFile, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "box read failed "<<error<<endl; return error; } boxes.sort(); Vector<int> assign; error = LoadBalance(assign, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl; return error; } BoxLayout readplan2(boxes, assign); readplan2.close(); error = read(testFile, readlevel2, "level2 state vector", readplan2); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl; return error; } testFile.setGroupToLevel(1); error = read(testFile, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "box read failed "<<error<<endl; return error; } error = LoadBalance(assign, boxes); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayout LoadBalance failed "<<error<<endl; return error; } BoxLayout readplan1(boxes, assign); readplan1.close(); if ( verbose ) { pout() << "readplan1: " << procID() << "...." << readplan1 << endl; pout() << "readplan2: " << procID() << "...." << readplan2 << endl; } error = read(testFile, readlevel1, "level1 state vector", readplan1); if (error != 0) { if ( verbose ) pout() << indent2 << "BoxLayoutData<BaseFab<int>> read failed "<<error<<endl; return error; } if ( verbose ) pout() << plan1<<readplan1<<endl; // real test of IO, make sure the data is the same coming and going DataIterator l1 = level1.dataIterator(); DataIterator rl1 = readlevel1.dataIterator(); DataIterator l2 = level2.dataIterator(); DataIterator rl2 = readlevel2.dataIterator(); if (level1.boxLayout().size() != readlevel1.boxLayout().size()) { if ( verbose ) pout() << indent2 << "level1.size() != readl1.size() read failed "<<error<<endl; return 1; } if (level2.boxLayout().size() != readlevel2.boxLayout().size()) { if ( verbose ) pout() << indent2 << "level2.size() != readl2.size() read failed "<<error<<endl; return 1; } // we can assume that BoxLayout IO is tested in HDF5boxIO BaseFab<int>* before, *after; for (; l1.ok(); ++l1, ++rl1) { before = &(level1[l1()]); after = &(readlevel1[rl1()]); for (int c=0; c<before->nComp(); ++c) { for (BoxIterator it(level1.box(l1())); it.ok(); ++it) { if ((*before)(it(), c) != (*after)(it(), c)) { if ( verbose ) pout() << indent2 << "l1 != readl1 read failed "<<error<<endl; return 2; } } } } for (; l2.ok(); ++l2, ++rl2) { before = &(level2[l2()]); after = &(readlevel2[rl2()]); for (int c=0; c<before->nComp(); ++c) { for (BoxIterator it(level2.box(l2())); it.ok(); ++it) { if ((*before)(it(), c) != (*after)(it(), c)) { if ( verbose ) pout() << indent2 << "level2 != readlevel2 read failed "<<error<<endl; return 3; } } } } LevelData<FArrayBox> readState; Real dt, time; int refRatio; testFile.setGroup("/"); error = readLevel(testFile, 0, readState, dx, dt, time, b2, refRatio); if (error != 0) { if ( verbose ) pout() << indent2 << "readLevel failed "<<error<<endl; return error; } #ifndef CH_MPI // OK, now try to read one FArrayBox at a time // problem with DataIterator and running the out-of-core in parallel, so // have to think about that for now BVS. FArrayBox readFAB; Interval interval(1,2); testFile.setGroup("/"); int index=0; for (DataIterator dit(state.dataIterator()); dit.ok(); ++index,++dit) { FArrayBox& fab = state[dit()]; readFArrayBox(testFile, readFAB, 0, index, interval); for (BoxIterator it(state.box(dit())) ; it.ok() ; ++it) { if (readFAB(it(), 0) != fab(it(), 1)) { if ( verbose ) pout() << indent2 << "state != after for out-of-core "<<error<<endl; return 3; } } } #endif testFile.close(); CH_assert(!testFile.isOpen()); #endif // CH_USE_HDF5 return 0; }
long long fab(int n) { if(n==1||n==2) return 1; else return fab(n-1)+fab(n-2); }
/** The "checksum" is a function of all the field data at a given step. * That field data, in turn, is a function of the checksum at the previous * step. That way I can be pretty sure that when this restart thing * produces the expected hdf5 files, it's not just fooling me. */ void EBRestart::updateChecksums( Vector<LevelData<EBCellFAB>*>& a_ebvector, int a_nlevs, EBRestart::CheckSumVect& a_checksums ) { for ( int lev=0; lev<a_nlevs; ++lev ) { LevelData<EBCellFAB>& field( *a_ebvector[lev] ); DataIterator dit = field.dataIterator(); for (dit.begin(); dit.ok(); ++dit) { EBCellFAB& ebcf((*a_ebvector[lev])[dit]); BaseFab<Real>& fab(ebcf.getSingleValuedFAB()); a_checksums[lev].len_reg += fab.box().numPts(); a_checksums[lev].len_irreg += ebcf.getEBISBox().getEBGraph().getIrregCells(fab.box()).numPts(); for ( int i=0; i<fab.box().numPts(); ++i ) { long x = long(fab.dataPtr()[i]); a_checksums[lev].sum += x*x; } } // // MPI-reduce the various members of a_checksums[lev]. // #ifdef CH_MPI Real all_proc_sum; Real proc_sum( a_checksums[lev].sum ); if ( MPI_SUCCESS != MPI_Allreduce(&proc_sum, &all_proc_sum, 1, MPI_CH_REAL, MPI_SUM, Chombo_MPI::comm) ) { MayDay::Error("Failure in MPI_Allreduce()."); } a_checksums[lev].sum = long(all_proc_sum); // There's no MPI_CH_LONG. Maybe I should make .sum Real then. // // Reduce a_checksums[lev].len_reg // Real all_proc_len_reg; Real proc_len_reg( a_checksums[lev].len_reg ); if ( MPI_SUCCESS != MPI_Allreduce(&proc_len_reg, &all_proc_len_reg, 1, MPI_CH_REAL, MPI_SUM, Chombo_MPI::comm) ) { MayDay::Error("Failure in MPI_Allreduce()."); } a_checksums[lev].len_reg = long(all_proc_len_reg); // // Reduce a_checksums[lev].len_irreg // Real all_proc_len_irreg; Real proc_len_irreg( a_checksums[lev].len_irreg ); if ( MPI_SUCCESS != MPI_Allreduce(&proc_len_irreg, &all_proc_len_irreg, 1, MPI_CH_REAL, MPI_SUM, Chombo_MPI::comm) ) { MayDay::Error("Failure in MPI_Allreduce()."); } a_checksums[lev].len_irreg = long(all_proc_len_irreg); #endif } }