bool OctNode::check_for_refine() { OctNode* g; bool rc = false; if (max_refine_level == 0) { return false; } root->clear_refine_flags(); for (int i = 0; i < get_local_node_cnt(); i++) { g = (get_local_node(i)); g->set_refine_flags(); g->propagate_refine_flags_up(); } for (int lev = get_max_level(); lev >= 0; lev--) { for (int i = 0; i < get_local_node_cnt(); i++) { g = (get_local_node(i)); if (g->get_level() == lev) { g->enforce_proper_nesting(); g->propagate_refine_flags_up(); } } reduce_refine_flags(); } rc = root->use_refine_flags(); if (rc) { root->find_local_nodes(); } return rc; }
Real MultiGrid::get_phi_at(Real x, Real y, Real z) { Real p, tmp; MultiGrid* g; p = 0.0; for (int l = 0; l < get_local_node_cnt(); l++) { g = dynamic_cast<MultiGrid*>(get_local_node(l)); if (MPI_rank() == g->proc()) { for (int k = 1; k < PNX - 1; k++) { if (z >= g->MultiGrid::zf(k) && z < g->MultiGrid::zf(k + 1)) { for (int j = 1; j < PNX - 1; j++) { if (y >= g->MultiGrid::yf(j) && y < g->MultiGrid::yf(j + 1)) { for (int i = 1; i < PNX - 1; i++) { // printf("%e %e %e\n", g->MultiGrid::xf(i), x, g->MultiGrid::xf(i + 1)); if (x >= g->MultiGrid::xf(i) && x < g->MultiGrid::xf(i + 1)) { if (!g->poisson_zone_is_refined(i, j, k)) { p = g->phi(i, j, k); // printf("%e\n", p); } } } } } } } } } tmp = p; MPI_Allreduce(&tmp, &p, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD ); return p; }
Real MultiGrid::vcycle() { MPI_datatypes_init(); Real part, sum; MultiGrid** list = new MultiGrid*[get_local_node_cnt()]; for (int i = 0; i < get_local_node_cnt(); i++) { list[i] = dynamic_cast<MultiGrid*>(get_local_node(i)); } run_program(list, get_local_node_cnt(), cs, COMPUTE_STAGE_MAX); delete[] list; sum = 0.0; for (int i = 0; i < OctNode::get_local_node_cnt(); i++) { sum += dynamic_cast<MultiGrid*>(OctNode::get_local_node(i))->st0; } part = sum; MPI_Allreduce(&part, &sum, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD ); return sum; }
static void proc_read(void) { FILE * fd; char buf[512], *p, *s; int w; intf_t *i; if (!(fd = fopen(c_path, "r"))) quit("Unable to open file %s: %s\n", c_path, strerror(errno)); fgets(buf, sizeof(buf), fd); fgets(buf, sizeof(buf), fd); for (; fgets(buf, sizeof(buf), fd);) { b_cnt_t rx_errors, rx_drop, rx_fifo, rx_frame, rx_compressed; b_cnt_t rx_multicast, tx_errors, tx_drop, tx_fifo, tx_frame; b_cnt_t tx_compressed, tx_multicast; if (buf[0] == '\r' || buf[0] == '\n') continue; if (!(p = strchr(buf, ':'))) continue; *p = '\0'; s = (p + 1); for (p = &buf[0]; *p == ' '; p++); /* * XXX: get_show_only_running */ if ((i = lookup_intf(get_local_node(), p, 0, 0)) == NULL) continue; w = sscanf(s, "%llu %llu %llu %llu %llu %llu %llu %llu %llu %llu " "%llu %llu %llu %llu %llu %llu\n", &i->i_rx_bytes.r_total, &i->i_rx_packets.r_total, &rx_errors, &rx_drop, &rx_fifo, &rx_frame, &rx_compressed, &rx_multicast, &i->i_tx_bytes.r_total, &i->i_tx_packets.r_total, &tx_errors, &tx_drop, &tx_fifo, &tx_frame, &tx_compressed, &tx_multicast); if (w != 16) continue; update_attr(i, ERRORS, rx_errors, tx_errors, RX_PROVIDED|TX_PROVIDED); update_attr(i, DROP, rx_drop, tx_drop, RX_PROVIDED|TX_PROVIDED); update_attr(i, FIFO, rx_fifo, tx_fifo, RX_PROVIDED|TX_PROVIDED); update_attr(i, FRAME, rx_frame, tx_frame, RX_PROVIDED|TX_PROVIDED); update_attr(i, COMPRESSED, rx_compressed, tx_compressed, RX_PROVIDED|TX_PROVIDED); update_attr(i, MULTICAST, rx_multicast, tx_multicast, RX_PROVIDED|TX_PROVIDED); notify_update(i); increase_lifetime(i, 1); } fclose(fd); }
void GridSod::run(int argc, char* argv[]) { //shadow_on(); Real dxmin = dynamic_cast<GridSod*>(get_root())->get_dx() / Real(1 << get_max_level_allowed()); initialized1 = true; line_N = int(2.0 * GRID_DIM / dxmin + 1.5); line_avg = new Vector<Real, 5> [line_N]; line_bin_cnt = new int[line_N]; line_avg_tmp = new Vector<Real, 5> [line_N]; line_bin_cnt_tmp = new int[line_N]; for (int i = 0; i < line_N; i++) { line_bin_cnt[i] = 0; line_avg[i] = Vector<Real, 5>(0.0); } HydroGrid::run(argc, argv); GridSod* g; const int M = (GNX - 2 * BW) * (GNX - 2 * BW) * (GNX - 2 * BW); Real ad[M]; Real ap[M]; Real av[M]; Real xpos[M]; Real l2 = 0.0; dxmin = dynamic_cast<GridSod*>(get_root())->get_dx() / Real(1 << get_max_level_allowed()); for (int l = 0; l < get_local_node_cnt(); l++) { g = dynamic_cast<GridSod*>(get_local_node(l)); int j = 0; j = 0; const Real dv = pow(g->get_dx(), 3); for (Indexer3d i(BW, GNX - BW - 1); !i.end(); i++) { if (!g->zone_is_refined(i[0], i[1], i[2])) { xpos[j] = g->xsod(i); sod_state_t state; exact_sod(&state, &sod_init, xpos[j], get_time()); ad[j] = state.rho; av[j] = state.v; ap[j] = state.p; j++; } } j = 0; for (Indexer3d i(BW, GNX - BW - 1); !i.end(); i++) { int ri; if (!oblique) { ri = (xpos[j] + GRID_DIM) / dxmin; } else { ri = (xpos[j] / sqrt(3.0) + GRID_DIM) / dxmin; } if (!g->zone_is_refined(i[0], i[1], i[2]) && g->yzsod(i) < 0.1) { g->line_avg[ri][0] += (*g)(i).rho(); if (oblique) { g->line_avg[ri][1] += ((*g)(i).vx() + (*g)(i).vy() + (*g)(i).vz()) / sqrt(3.0); } else { g->line_avg[ri][1] += (*g)(i).vx(); } // g->line_avg[ri][2] += (*g)(i).vy(); // g->line_avg[ri][3] += (*g)(i).vz(); g->line_avg[ri][4] += (*g)(i).pg(); g->line_bin_cnt[ri]++; l2 += pow((*g)(i).rho() - ad[j], 2) * pow(g->get_dx(), 3); j++; } } } g = dynamic_cast<GridSod*>(get_root()); for (int i = 0; i < line_N; i++) { g->line_avg_tmp[i] = g->line_avg[i]; g->line_bin_cnt_tmp[i] = g->line_bin_cnt[i]; } MPI_Allreduce(g->line_bin_cnt_tmp, g->line_bin_cnt, g->line_N, MPI_INTEGER, MPI_SUM, MPI_COMM_WORLD ); MPI_Allreduce(g->line_avg_tmp, g->line_avg, g->line_N * 5, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD ); Real tmp = l2; MPI_Allreduce(&tmp, &l2, 1, MPI_DOUBLE_PRECISION, MPI_SUM, MPI_COMM_WORLD ); l2 /= 8.0 * GRID_DIM * GRID_DIM * GRID_DIM; printf("L2 error = %e\n", l2); diag_mode = true; get_root()->output("S", 0.0, GNX, BW); if (MPI_rank() == 0) { Real* xpos = new double[line_N]; Real* ad = new double[line_N]; Real* av = new double[line_N]; Real* ap = new double[line_N]; for (int i = 0; i < g->line_N; i++) { if (oblique) { xpos[i] = ((i + 0.5) * dxmin - GRID_DIM) * sqrt(3.0); } else { xpos[i] = (i + 0.5) * dxmin - GRID_DIM; } sod_state_t state; exact_sod(&state, &sod_init, xpos[i], get_time()); ad[i] = state.rho; av[i] = state.v; ap[i] = state.p; } FILE* fp = fp = fopen("cmp.d.dat", "wt"); for (int i = 0; i < g->line_N; i++) { if (g->line_bin_cnt[i] != 0) { g->line_avg[i] /= Real(g->line_bin_cnt[i]); fprintf(fp, "%e %e %e\n", -xpos[i], g->line_avg[i][0], ad[i]); } } fclose(fp); fp = fp = fopen("cmp.v.dat", "wt"); for (int i = 0; i < g->line_N; i++) { if (g->line_bin_cnt[i] != 0) { fprintf(fp, "%e %e %e\n", -xpos[i], g->line_avg[i][1], av[i]); } } fclose(fp); fp = fp = fopen("cmp.p.dat", "wt"); for (int i = 0; i < g->line_N; i++) { if (g->line_bin_cnt[i] != 0) { fprintf(fp, "%e %e %e\n", -xpos[i], g->line_avg[i][4], ap[i]); } } fclose(fp); fp = fp = fopen("cmp.u.dat", "wt"); for (int i = 0; i < g->line_N; i++) { if (g->line_bin_cnt[i] != 0) { fprintf(fp, "%e %e %e\n", -xpos[i], g->line_avg[i][4] / (State::gamma - 1.0) / g->line_avg[i][0], ap[i] / (State::gamma - 1.0) / ad[i]); } } fclose(fp); fp = fp = fopen("cmp.s.dat", "wt"); for (int i = 0; i < g->line_N; i++) { if (g->line_bin_cnt[i] != 0) { fprintf(fp, "%e %e %e\n", -xpos[i], log(pow(g->line_avg[i][4] / (State::gamma - 1.0), (1.0 / State::gamma)) / g->line_avg[i][0]), log(pow(ap[i] / (State::gamma - 1.0), 1.0 / State::gamma) / ad[i])); } } fclose(fp); //printf("%e\n", etot); } }
static void sysctl_read(void) { int mib[] = {CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0}; size_t n; char *buf, *next, *lim; if (sysctl(mib, 6, NULL, &n, NULL, 0) < 0) quit("sysctl() failed"); if (c_debug) fprintf(stderr, "sysctl 1-pass n=%d\n", (int) n); buf = xcalloc(1, n); if (sysctl(mib, 6, buf, &n, NULL, 0) < 0) quit("sysctl() failed"); if (c_debug) fprintf(stderr, "sysctl 2-pass n=%d\n", (int) n); lim = buf + n; next = buf; while (next < lim) { char ifname[IFNAME_MAX]; int iflen = sizeof(ifname) - 1; struct if_msghdr *ifm, *nextifm; struct sockaddr_dl *sdl; struct item *it; memset(ifname, 0, sizeof(ifname)); ifm = (struct if_msghdr *) next; if (ifm->ifm_type != RTM_IFINFO) break; next += ifm->ifm_msglen; while (next < lim) { nextifm = (struct if_msghdr *) next; if (nextifm->ifm_type != RTM_NEWADDR) break; next += nextifm->ifm_msglen; } sdl = (struct sockaddr_dl *) (ifm + 1); if (sdl->sdl_family != AF_LINK) continue; if (cfg_show_only_running && !(ifm->ifm_flags & IFF_UP)) continue; if (iflen > sd->sdl_nlen) iflen = sdl->sdl_nlen; memcpy(ifname, sdl->sdl_data, iflen); if (c_debug) fprintf(stderr, "Processing %s\n", ifname); it = lookup_item(get_local_node(), ifname, 0, 0); if (it == NULL) continue; set_item_attrs(it, ATTR(BYTES), ATTR(PACKETS), ATTR(BYTES)); update_attr(it, ATTR(PACKETS), ifm->ifm_data.ifi_ipackets, ifm->ifm_data.ifi_opackets, RX_PROVIDED | TX_PROVIDED); update_attr(it, ATTR(BYTES), ifm->ifm_data.ifi_ibytes, ifm->ifm_data.ifi_obytes, RX_PROVIDED | TX_PROVIDED); update_attr(it, ATTR(ERRORS), ifm->ifm_data.ifi_ierrors, ifm->ifm_data.ifi_oerrors, RX_PROVIDED | TX_PROVIDED); update_attr(it, ATTR(COLLISIONS), 0, ifm->ifm_data.ifi_collisions, TX_PROVIDED); update_attr(it, ATTR(MULTICAST), ifm->ifm_data.ifi_imcasts, 0, RX_PROVIDED); update_attr(it, ATTR(DROP), 0, ifm->ifm_data.ifi_iqdrops, TX_PROVIDED); notify_update(it, NULL); increase_lifetime(it, 1); } xfree(buf); }
static void kstat_do_read(void) { kstat_ctl_t * kc; kstat_t * kst; kstat_named_t * kn, *kn2; intf_t * i; if (!(kc = kstat_open())) quit("kstat_open() failed"); if ((kst = kstat_lookup(kc, NULL, -1, NULL))) { for (; kst; kst = kst->ks_next) { if (strcmp(kst->ks_class, "net")) continue; if (kstat_read(kc, kst, NULL) < 0) continue; if (!strcmp(kst->ks_name, "zero_copy")) continue; i = lookup_intf(get_local_node(), kst->ks_name, 0, 0); if (NULL == i) continue; #define KSTAT_GET(S) (kstat_named_t *) kstat_data_lookup(kst, #S) if ((kn = KSTAT_GET(rbytes64))) { i->i_rx_bytes.r_total = kn->value.ui64; i->i_rx_bytes.r_is64bit = 1; } else if ((kn = KSTAT_GET(rbytes))) i->i_rx_bytes.r_total = kn->value.ui32; if ((kn = KSTAT_GET(ipackets64))) { i->i_rx_packets.r_total = kn->value.ui64; i->i_rx_packets.r_is64bit = 1; } else if ((kn = KSTAT_GET(ipackets))) i->i_rx_packets.r_total = kn->value.ui32; if ((kn = KSTAT_GET(obytes64))) i->i_tx_bytes.r_total = kn->value.ui64; else if ((kn = KSTAT_GET(obytes))) i->i_tx_bytes.r_total = kn->value.ui32; if ((kn = KSTAT_GET(opackets64))) i->i_tx_packets.r_total = kn->value.ui64; else if ((kn = KSTAT_GET(opackets))) i->i_tx_packets.r_total = kn->value.ui32; if ((kn = KSTAT_GET(ierror)) && (kn2 = KSTAT_GET(oerrors))) update_attr(i, ERRORS, kn->value.ui32, kn2->value.ui32, RX_PROVIDED | TX_PROVIDED); if ((kn = KSTAT_GET(multircv64)) && (kn2 = KSTAT_GET(multixmt64))) update_attr(i, MULTICAST, kn->value.ui64, kn2->value.ui64, RX_PROVIDED | TX_PROVIDED); else if ((kn = KSTAT_GET(multircv)) && (kn2 = KSTAT_GET(multixmt))) update_attr(i, MULTICAST, kn->value.ui32, kn2->value.ui32, RX_PROVIDED | TX_PROVIDED); if ((kn = KSTAT_GET(brdcstrcv)) && (kn2 = KSTAT_GET(brdcstxmt))) update_attr(i, BROADCAST, kn->value.ui32, kn2->value.ui32, RX_PROVIDED | TX_PROVIDED); #undef KSTAT_GET notify_update(i); increase_lifetime(i, 1); } } kstat_close(kc); }