void Read(char ch1, char ch2, const char * cmd) { int len; char buf[500]; char * line; if (sock == -1) { printf("# socket is not open\n"); Where(); return; } len = read(sock, buf, 500); if (len < 0) { printf("# read() returned error %s\n", Explain()); } else { buf[len] = 0; printf("# read() returned:\n"); for (line = strtok(buf, "\n\r"); line; line = strtok(nil, "\n\r")) printf("# %s\n", line); } Where(); }
void TogBlk(char ch1, char ch2, const char * cmd) { int block; if (sock == -1) { printf("# socket is not open\n"); Where(); return; } switch (fcntl(sock, F_GETFL, 0)) { case 0: block = 1; break; default: block = 0; break; case -1: printf("# fcntl(F_GETFL) returned error %s\n", Explain()); Where(); return; } if (ioctl(sock, FIONBIO, &block)) printf( "# ioctl(FIONBIO, %s) returned error %s\n", block ? "true" : "false", Explain()); else printf("# Socket is now %s\n", block ? "nonblocking" : "blocking"); Where(); }
void Listen(char ch1, char ch2, const char * cmd) { if (sock == -1) { printf("# socket is not open\n"); Where(); return; } if (listen(sock, 5)) { printf("# listen() returned error %s\n", Explain()); Where(); } }
void oet(Ptr<Int> p) { setReadStride(1); setWriteStride(1); Int evens = *p; Int odds = *(p+1); For (Int count = 0, count < 16, count++) Int evens2 = min(evens, odds); Int odds2 = max(evens, odds); Int evens3 = rotate(evens2, 15); Int odds3 = odds2; Where (index() != 15) odds2 = min(evens3, odds3); End Where (index() != 0) evens2 = rotate(max(evens3, odds3), 1); End evens = evens2; odds = odds2; End *p = evens; *(p+1) = odds; }
void Prepare(void) { C[0][0] = 1; for (int i = 1; i <= nTree; i++) { C[0][i] = 1; for (int j = 1; j <= K; j++) C[j][i] = C[j][i - 1] + C[j - 1][i - 1]; } std::sort(Set + 1, Set + 1 + nTree); std::sort(S + 1, S + 1 + nTree, cmpII); S[0].x = S[0].y = -INF; S[nTree + 1].x = S[nTree + 1].y = INF; for (int i = 1; i <= nTree; i++) { int t = S[i].P = Where(S[i].y); sumRow[t]++; S[i].L = S[i].y == S[i - 1].y ? S[i - 1].L + 1 : 1; } std::sort(S + 1, S + 1 + nTree, cmp); int last = 0; for (int i = 1; i <= nTree; i++) { if (S[i].x == S[i - 1].x) Sup[i] = Sup[i - 1] + 1; else {Sup[i] = 1; if (last) std::reverse(Sup + last, Sup + i); last = i;} } std::reverse(Sup + last, Sup + nTree + 1); T.n = nTree; }
void BenchSer(char ch1, char ch2, const char * cmd) { char * at; int requestSize; int responseSize; int packetSize; int count; int i; if (sock == -1) { printf("# socket is not open\n"); Where(); return; } at = BenchBuf; do { at += read(sock, at, 1024); *at = 0; } while (!strchr(BenchBuf, '\n')); sscanf(BenchBuf, "%d %d %d\n", &requestSize, &responseSize, &count); write(sock, BenchBuf, 1); for (i=0; i++<count; ) { packetSize = 0; do { packetSize += read(sock, BenchBuf, 8192); } while (packetSize < requestSize); write(sock, BenchBuf, responseSize); } }
void BenchCli(char ch1, char ch2, const char * cmd) { char * at; int requestSize; int responseSize; int packetSize; int contribSize; int count; int i; long startTime; long transTime; Sampler readSamp; Sampler writeSamp; Sampler sizeSamp; if (sock == -1) { printf("# socket is not open\n"); Where(); return; } if (sscanf(cmd, "%d %d %d", &requestSize, &responseSize, &count) != 3) { Usage(ch1, ch2); return; } InitSampler(&readSamp); InitSampler(&writeSamp); InitSampler(&sizeSamp); write(sock, cmd, strlen(cmd)); read(sock, BenchBuf, 1); startTime = LMGetTicks(); for (i=0; i++<count; ) { transTime = LMGetTicks(); write(sock, BenchBuf, requestSize); Sample(&writeSamp, LMGetTicks()-transTime); packetSize = 0; transTime = LMGetTicks(); do { contribSize = read(sock, BenchBuf, 8192); packetSize += contribSize; Sample(&sizeSamp, contribSize); } while (packetSize < responseSize); Sample(&readSamp, LMGetTicks()-transTime); } printf("# Test took %d ticks.\n", LMGetTicks() - startTime); printf("# Read min: %2d max: %2d avg: %2.1f\n", readSamp.min, readSamp.max, ((double)readSamp.sum) / readSamp.count); printf("# Size min: %2d max: %2d avg: %2.1f\n", sizeSamp.min, sizeSamp.max, ((double)sizeSamp.sum) / sizeSamp.count); printf("# Write min: %2d max: %2d avg: %2.1f\n", writeSamp.min, writeSamp.max, ((double)writeSamp.sum) / writeSamp.count); }
void Socket(char ch1, char ch2, const char * line) { sock = socket(AF_APPLETALK, SOCK_STREAM, 0); if (sock == -1) { printf("# socket() returned error %s\n", Explain()); Where(); } }
void NRead(char ch1, char ch2, const char * cmd) { int nread; if (sock == -1) { printf("# socket is not open\n"); Where(); return; } if (ioctl(sock, FIONREAD, &nread)) printf("# ioctl(FIONREAD) returned error %s\n", Explain()); else printf("# %d bytes waiting to be read\n", nread); Where(); }
void Close(char ch1, char ch2, const char * cmd) { if (close(sock)) { printf("# close() returned error %s\n", Explain()); Where(); } sock = accsock; accsock = -1; }
void Select(char ch1, char ch2, const char * cmd) { int res; fd_set rdfds; fd_set wrfds; fd_set exfds; struct timeval delay; if (sock == -1) { printf("# socket is not open\n"); Where(); return; } FD_ZERO(&rdfds); FD_ZERO(&wrfds); FD_ZERO(&exfds); FD_SET(sock, &rdfds); FD_SET(sock, &wrfds); FD_SET(sock, &exfds); delay.tv_sec = 10; delay.tv_usec = 0; res = select(sock+1, &rdfds, &wrfds, &exfds, &delay); if (res < 0) { printf("# select() returned error %s\n", Explain()); } else if (!res) { printf("# select() timed out\n"); } else { printf( "# select() returned %s%s%s\n", FD_ISSET(sock, &rdfds) ? "canRead " : "", FD_ISSET(sock, &wrfds) ? "canWrite " : "", FD_ISSET(sock, &exfds) ? "exception " : ""); } Where(); }
void GetError(char ch1, char ch2, const char * cmd) { int err; socklen_t len = sizeof(int); if (sock == -1) { printf("# socket is not open\n"); Where(); return; } if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &len)) printf("# getsockopt(SOL_SOCKET, SO_ERROR) returned error %s\n", Explain()); else { errno = err; printf("# Asynchronous error was %d (%s)\n", err, Explain()); } Where(); }
void tri(Ptr<Int> p) { p = p + (me() << 4); Int n = *p; Int sum = 0; While (any(n > 0)) Where (n > 0) sum = sum+n; n = n-1; End End *p = sum; }
void Write(char ch1, char ch2, const char * line) { int len = strlen(line); int part; if (sock == -1) { printf("# socket is not open\n"); Where(); return; } for (; len; len -= part, line += part) { part = write(sock, line, len); if (part < 0) { printf("# write(\"%s\") returned error %s\n", line, Explain()); Where(); break; } } }
unsigned int Query::Clone(const Query *other) { // TRACE << "Cloning " << other->ToString() << "\n"; for (restrictions_t::const_iterator i = other->m_restrictions.begin(); i != other->m_restrictions.end(); ++i) { if (i->is_string) Restrict(i->which, i->rt, i->sval); else Restrict(i->which, i->rt, i->ival); } for (relations_t::const_iterator i = other->m_relations.begin(); i != other->m_relations.end(); ++i) { if (i->anditive) And(Subexpression((int)i->a), Subexpression((int)i->b)); else Or(Subexpression((int)i->a), Subexpression((int)i->b)); } unsigned int rc = Where(Subexpression(other->m_root)); if (rc) return rc; for (orderby_t::const_iterator i = other->m_orderby.begin(); i != other->m_orderby.end(); ++i) { rc = OrderBy(*i); if (rc) return rc; } for (orderby_t::const_iterator i = other->m_collateby.begin(); i != other->m_collateby.end(); ++i) { rc = CollateBy(*i); if (rc) return rc; } // TRACE << "Cloned: " << ToString() << "\n"; return 0; }
void Bind(char ch1, char ch2, const char * cmd) { struct sockaddr_atlk_sym addr; Str63 obj; if (sock == -1) { printf("# socket is not open\n"); Where(); return; } if (sscanf(cmd, "%s", (char *) (obj+1)) == 1) { addr.family = ATALK_SYMADDR; obj[0] = strlen((char *) (obj+1)); NBPSetEntity((Ptr) &addr.name, obj, "\pGUSIAtlkTest", "\p*"); } else {
static IO_clp bindIO(IOOffer_cl *io_offer, HeapMod_cl *hmod, Heap_clp *heap) { IO_clp res; IOData_Shm *shm; if(io_offer != NULL) { if(*heap) { /* We have some memory => bind using it */ Type_Any any; IDCClientBinding_clp cb; shm = SEQ_NEW(IOData_Shm, 1, Pvs(heap)); SEQ_ELEM(shm, 0).buf.base = HeapMod$Where(hmod, *heap, &(SEQ_ELEM(shm, 0).buf.len)); SEQ_ELEM(shm, 0).param.attrs = 0; SEQ_ELEM(shm, 0).param.awidth = PAGE_WIDTH; SEQ_ELEM(shm, 0).param.pwidth = PAGE_WIDTH; cb = IOOffer$ExtBind(io_offer, shm, Pvs(gkpr), &any); if(!ISTYPE(&any, IO_clp)) { eprintf("udp_socket.c [bindIO]: IOOffer$ExtBind failed.\n"); if(cb) IDCClientBinding$Destroy(cb); RAISE_TypeSystem$Incompatible(); } res = NARROW (&any, IO_clp); } else { /* Just bind to offer and create a heap afterwards. */ res = IO_BIND(io_offer); shm = IO$QueryShm(res); if(SEQ_LEN(shm) != 1) eprintf("udp_socket.c [bindIO]: " "got > 1 data areas in channel!\n"); /* Ignore extra areas for now */ *heap = HeapMod$NewRaw(hmod, SEQ_ELEM(shm, 0).buf.base, SEQ_ELEM(shm, 0).buf.len); } return res; } return (IO_cl *)NULL; }
void Shutdown(char ch1, char ch2, const char * cmd) { int what; if (sock == -1) { printf("# socket is not open\n"); Where(); return; } if (sscanf(cmd, "%d", &what) != 1) { Usage(ch1, ch2); return; } if (shutdown(sock, what)) printf("# shutdown(%d) returned error %s\n", what, Explain()); }
/** expression without query parameters */ std::string operator()() { return std::string("SELECT ") + //helper::impl_select_part<0,Fields...>()() + Fields()() + std::string(" ") + From()() + (std::is_same<Where,none>::value ? std::string("") : Where()() + (std::is_same<GroupBy,none>::value ? std::string("") : GroupBy()() + (std::is_same<Having,none>::value ? std::string("") : Having()()))) + (std::is_same<OrderBy,none>::value ? std::string("") : OrderBy()()); }
std::string operator()(binder<Args...>& b) { return std::string("DELETE ") + From()(b) + Where()(b); }
/** Empty parameter list */ std::string operator()() { return std::string("DELETE ") + From()() + Where()(); }
// Advance the solution by "a_dt" by using an unsplit method. // "a_finerFluxRegister" is the flux register with the next finer level. // "a_coarseFluxRegister" is flux register with the next coarser level. // If source terms do not exist, "a_S" should be null constructed and not // defined (i.e. its define() should not be called). Real LevelPluto::step(LevelData<FArrayBox>& a_U, LevelData<FArrayBox> a_flux[CH_SPACEDIM], LevelFluxRegister& a_finerFluxRegister, LevelFluxRegister& a_coarserFluxRegister, LevelData<FArrayBox>& a_split_tags, const LevelData<FArrayBox>& a_UCoarseOld, const Real& a_TCoarseOld, const LevelData<FArrayBox>& a_UCoarseNew, const Real& a_TCoarseNew, const Real& a_time, const Real& a_dt, const Real& a_cfl) { CH_TIMERS("LevelPluto::step"); CH_TIMER("LevelPluto::step::setup" ,timeSetup); CH_TIMER("LevelPluto::step::update" ,timeUpdate); CH_TIMER("LevelPluto::step::reflux" ,timeReflux); CH_TIMER("LevelPluto::step::conclude",timeConclude); // Make sure everything is defined CH_assert(m_isDefined); CH_START(timeSetup); // Clear flux registers with next finer level if (m_hasFiner && (g_intStage == 1)) { a_finerFluxRegister.setToZero(); } // Setup an interval corresponding to the conserved variables Interval UInterval(0,m_numCons-1); { CH_TIME("setup::localU"); for (DataIterator dit = m_U.dataIterator(); dit.ok(); ++dit) { m_U[dit].setVal(0.0); // Gets rid of denormalized crap. m_U[dit].copy(a_U[dit]); } m_U.exchange(m_exchangeCopier); } // Fill m_U's ghost cells using fillInterp if (m_hasCoarser) { // Fraction "a_time" falls between the old and the new coarse times Real alpha = (a_time - a_TCoarseOld) / (a_TCoarseNew - a_TCoarseOld); // Truncate the fraction to the range [0,1] to remove floating-point // subtraction roundoff effects Real eps = 0.04 * a_dt / m_refineCoarse; if (Abs(alpha) < eps) alpha = 0.0; if (Abs(1.0-alpha) < eps) alpha = 1.0; // Current time before old coarse time if (alpha < 0.0) { MayDay::Error( "LevelPluto::step: alpha < 0.0"); } // Current time after new coarse time if (alpha > 1.0) { MayDay::Error( "LevelPluto::step: alpha > 1.0"); } // Interpolate ghost cells from next coarser level using both space // and time interpolation m_patcher.fillInterp(m_U, a_UCoarseOld, a_UCoarseNew, alpha, 0,0,m_numCons); } // Potentially used in boundary conditions m_patchPluto->setCurrentTime(a_time); // Use to restrict maximum wave speed away from zero Real maxWaveSpeed = 1.e-12; Real minDtCool = 1.e38; // The grid structure Grid *grid; static Time_Step Dts; Real inv_dt; #ifdef GLM_MHD glm_ch = g_coeff_dl_min*m_dx/(a_dt + 1.e-16)*a_cfl; // glm_ch = g_coeff_dl_min/(a_dt + 1.e-16)*a_cfl; /* If subcycling is turned off */ glm_ch = MIN(glm_ch,glm_ch_max*g_coeff_dl_min); #endif CH_STOP(timeSetup); g_level_dx = m_dx; // Beginning of loop through patches/grids. for (DataIterator dit = m_grids.dataIterator(); dit.ok(); ++dit){ CH_START(timeUpdate); // The current box Box curBox = m_grids.get(dit()); // The current grid of conserved variables FArrayBox& curU = m_U[dit]; // The current grid of volumes #if GEOMETRY != CARTESIAN const FArrayBox& curdV = m_dV[dit()]; #else const FArrayBox curdV; #endif #ifdef SKIP_SPLIT_CELLS // The current grid of split/unsplit tags FArrayBox& split_tags = a_split_tags[dit]; #else FArrayBox split_tags; #endif #if (TIME_STEPPING == RK2) // The current storage for flags (RK2 only) BaseFab<unsigned char>& flags = m_Flags[dit]; // Local temporary storage for conserved variables FArrayBox& curUtmp = m_Utmp[dit]; #else BaseFab<unsigned char> flags; FArrayBox curUtmp; #endif // The fluxes computed for this grid - used for refluxing and returning // other face centered quantities FluxBox flux; // Set the current box for the patch integrator m_patchPluto->setCurrentBox(curBox); Real minDtCoolGrid; grid = m_structs_grid[dit].getGrid(); IBEG = grid[IDIR].lbeg; IEND = grid[IDIR].lend; JBEG = grid[JDIR].lbeg; JEND = grid[JDIR].lend; KBEG = grid[KDIR].lbeg; KEND = grid[KDIR].lend; NX1 = grid[IDIR].np_int; NX2 = grid[JDIR].np_int; NX3 = grid[KDIR].np_int; NX1_TOT = grid[IDIR].np_tot; NX2_TOT = grid[JDIR].np_tot; NX3_TOT = grid[KDIR].np_tot; SetRBox(); /* RBox structures must be redefined for each patch */ g_dt = a_dt; g_time = a_time; g_maxRiemannIter = 0; PLM_CoefficientsSet (grid); /* -- these may be needed by shock flattening algorithms */ #if RECONSTRUCTION == PARABOLIC PPM_CoefficientsSet (grid); #endif // reset time step coefficients if (Dts.cmax == NULL) Dts.cmax = ARRAY_1D(NMAX_POINT, double); int id; Dts.inv_dta = 1.e-18; Dts.inv_dtp = 1.e-18; Dts.dt_cool = 1.e18; Dts.cfl = a_cfl; Where(-1, grid); /* -- store grid for subsequent calls -- */ // Take one step m_patchPluto->advanceStep (curU, curUtmp, curdV, split_tags, flags, flux, &Dts, curBox, grid); inv_dt = Dts.inv_dta + 2.0*Dts.inv_dtp; maxWaveSpeed = Max(maxWaveSpeed, inv_dt); // Now the inverse of the timestep minDtCool = Min(minDtCool, Dts.dt_cool/a_cfl); CH_STOP(timeUpdate); CH_START(timeReflux); // Do flux register updates for (int idir = 0; idir < SpaceDim; idir++) { // Increment coarse flux register between this level and the next // finer level - this level is the next coarser level with respect // to the next finer level if (m_hasFiner) { a_finerFluxRegister.incrementCoarse(flux[idir],a_dt,dit(), UInterval, UInterval,idir); } // Increment fine flux registers between this level and the next // coarser level - this level is the next finer level with respect // to the next coarser level if (m_hasCoarser) { a_coarserFluxRegister.incrementFine(flux[idir],a_dt,dit(), UInterval, UInterval,idir); } } CH_STOP(timeReflux); } CH_START(timeConclude); { CH_TIME("conclude::copyU"); // Now that we have completed the updates of all the patches, we copy the // contents of temporary storage, U, into the permanent storage, a_U. for(DataIterator dit = m_U.dataIterator(); dit.ok(); ++dit){ a_U[dit].copy(m_U[dit]); } } // Find the minimum of dt's over this level Real local_dtNew = 1. / maxWaveSpeed; local_dtNew = Min(local_dtNew,minDtCool); Real dtNew; { CH_TIME("conclude::getDt"); #ifdef CH_MPI #if (TIME_STEPPING == RK2) && (COOLING == NO) if (g_intStage == 1) { #endif int result = MPI_Allreduce(&local_dtNew, &dtNew, 1, MPI_CH_REAL, MPI_MIN, Chombo_MPI::comm); if(result != MPI_SUCCESS){ //bark!!! MayDay::Error("sorry, but I had a communcation error on new dt"); } #if (TIME_STEPPING == RK2) && (COOLING == NO) } else { dtNew = local_dtNew; } #endif #else dtNew = local_dtNew; #endif } CH_STOP(timeConclude); // Return the maximum stable time step return dtNew; }