void CommEvent::writeOTF2Leave(OTF2_EvtWriter * writer, QMap<QString, int> * attributeMap) { // For coalesced steps, don't write attributes if (step < 0) { // Finally write enter event OTF2_EvtWriter_Leave(writer, NULL, exit, function); return; } OTF2_AttributeList * attribute_list = OTF2_AttributeList_New(); // Phase and Step OTF2_AttributeValue phase_value; phase_value.uint32 = phase; OTF2_AttributeList_AddAttribute(attribute_list, attributeMap->value("phase"), OTF2_TYPE_UINT64, phase_value); OTF2_AttributeValue step_value; step_value.uint32 = step; OTF2_AttributeList_AddAttribute(attribute_list, attributeMap->value("step"), OTF2_TYPE_UINT64, step_value); // Write metrics for (QMap<QString, int>::Iterator attr = attributeMap->begin(); attr != attributeMap->end(); ++attr) { if (!hasMetric(attr.key())) continue; OTF2_AttributeValue attr_value; attr_value.uint64 = getMetric(attr.key()); OTF2_AttributeList_AddAttribute(attribute_list, attributeMap->value(attr.key()), OTF2_TYPE_UINT64, attr_value); OTF2_AttributeValue agg_value; agg_value.uint64 = getMetric(attr.key(), true); OTF2_AttributeList_AddAttribute(attribute_list, attributeMap->value(attr.key() + "_agg"), OTF2_TYPE_UINT64, agg_value); } // Finally write enter event OTF2_EvtWriter_Leave(writer, attribute_list, exit, function); }
/** * 頂点を、順番にcollapseしていく。 * ただし、当該頂点から出るエッジの長さが短いものから、優先的にcollapseしていく。 */ void MTT::collapse(RoadGraph* roads, float w1, float w2, float w3, std::vector<RoadGraph*>* sequence) { qDebug() << "collapse start."; PCA pca; doPCA(roads, pca); RoadVertexDesc bdry1_desc, bdry2_desc; findBoundaryVertices(roads, bdry1_desc, bdry2_desc); while (true) { int count = 0; sequence->push_back(GraphUtil::copyRoads(roads)); float min_metric = std::numeric_limits<float>::max(); RoadVertexDesc min_v_desc1; // to be collapsed to the other one RoadVertexDesc min_v_desc2; RoadEdgeIter ei, eend; for (boost::tie(ei, eend) = boost::edges(roads->graph); ei != eend; ++ei) { if (!roads->graph[*ei]->valid) continue; count++; RoadVertexDesc src = boost::source(*ei, roads->graph); RoadVertexDesc tgt = boost::target(*ei, roads->graph); if (bdry2_desc == src || bdry2_desc == tgt) { int k = 0; } float metric = getMetric(roads, src, tgt, w1, w2, w3, pca); if (metric < min_metric) { min_metric = metric; min_v_desc1 = src; min_v_desc2 = tgt; } metric = getMetric(roads, tgt, src, w1, w2, w3, pca); if (metric < min_metric) { min_metric = metric; min_v_desc1 = tgt; min_v_desc2 = src; } } if (count <= 1) break; // 頂点min_v_desc1を、min_v_desc2へcollapseする GraphUtil::collapseVertex(roads, min_v_desc1, min_v_desc2); } qDebug() << "collapse done."; }
int glyphCompare(const void *a, const void *b) { unsigned char *c1 = (unsigned char *) a; unsigned char *c2 = (unsigned char *) b; TexGlyphInfo tgi1; TexGlyphInfo tgi2; getMetric(fontinfo, *c1, &tgi1); getMetric(fontinfo, *c2, &tgi2); return tgi2.height - tgi1.height; }
void CommEvent::calculate_differential_metric(QString metric_name, QString base_name) { long long max_parent = getMetric(base_name, true); long long max_agg_parent = 0; if (comm_prev) max_agg_parent = (comm_prev->getMetric(base_name)); addMetric(metric_name, std::max(0., getMetric(base_name)- max_parent), std::max(0., getMetric(base_name, true)- max_agg_parent)); }
RRTNode *RRT2DExpansionAlgorithm::do_expansion(RRTNode *from, RRTNode *to){ RRT2DConfiguration* c_from = dynamic_cast<RRT2DConfiguration*>(from->getData()); RRT2DConfiguration* c_to = dynamic_cast<RRT2DConfiguration*>(to->getData()); RRT2DConfiguration* c_expand = new RRT2DConfiguration; double dist = getMetric()->calcDistance(from,to); if(dist > 0.5){ double unit_vector_x = (c_to->getX() - c_from->getX())/dist; double unit_vector_y = (c_to->getY() - c_from->getY())/dist; int coord = (int)(unit_vector_x * getExpansionDistance()+c_from->getX()); if (coord > (int)getCollisionMapW()) coord = getCollisionMapW(); if (coord < 0) coord = 0; c_expand->setX(coord); coord = (int)(unit_vector_y * getExpansionDistance()+c_from->getY()); if (coord > (int)getCollisionMapH()) coord = getCollisionMapH(); if (coord < 0) coord = 0; c_expand->setY(coord); RRTNode* expanded = new RRTNode; expanded->setDataP(c_expand); return expanded; } else{ delete c_expand; return NULL; } }
void CommEvent::calculate_differential_metric(QString metric_name, QString base_name, bool aggregates) { long long max_parent = metrics->getMetric(base_name, true); long long max_agg_parent = 0; if (aggregates && comm_prev) max_agg_parent = (comm_prev->metrics->getMetric(base_name)); if (aggregates) metrics->addMetric(metric_name, std::max(0., getMetric(base_name)- max_parent), std::max(0., getMetric(base_name, true)- max_agg_parent)); else metrics->addMetric(metric_name, std::max(0., getMetric(base_name)- max_parent)); }
/* Execute metric at default instance. Assumes only one returned result */ cffFixed MMFXExecMetric(hotCtx g, unsigned id) { MMFXCtx h = g->ctx.MMFX; unsigned length; unsigned cstrInx; cffFixed result[T2_MAX_OP_STACK]; if (getMetric(h, id, &cstrInx, &length)) { hotMsg(g, hotFATAL, "Metric id <%u> not found", id); } cffExecLocalMetric(g->ctx.cff, &h->cstrs.array[cstrInx], h->cstrs.cnt - cstrInx, result); return result[0]; }
int main(int argc, char *argv[]) { int c; TexGlyphInfo tgi; int usageError = 0; char *varname, *fontname; XFontStruct *xfont; int i; if (argc == 3) { varname = argv[1]; fontname = argv[2]; } else usageError = 1; if (usageError) { fprintf(stderr, "\n"); fprintf(stderr, "usage: genfontfile variable_name X_font_name\n"); fprintf(stderr, "\n"); exit(1); } dpy = XOpenDisplay(NULL); if (!dpy) { fprintf(stderr, "could not open display\n"); exit(1); } /* find an OpenGL-capable RGB visual with depth buffer */ xfont = XLoadQueryFont(dpy, fontname); if (!xfont) { fprintf(stderr, "could not get load X font: %s\n", fontname); exit(1); } fontinfo = SuckGlyphsFromServer(dpy, xfont->fid); if (!fontinfo) { fprintf(stderr, "could not get font glyphs\n"); exit(1); } printf("static const %s[][%d] = {\n", varname, fontinfo->max_ascent + fontinfo->max_descent + 2); for (c = 32; c < 256; c++) { getMetric(fontinfo, c, &tgi); printGlyph(fontinfo, c); } printf(" };\n"); return 0; }
int main(int argc, char *argv[]) { int texw, texh; unsigned char *texarea, *texbitmap; FILE *file; int len, stride; unsigned char *glist; int width, height; int px, py, maxheight; TexGlyphInfo tgi; int usageError = 0; char *fontname, *filename; XFontStruct *xfont; int endianness; int i, j; texw = texh = 256; glist = " ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijmklmnopqrstuvwxyz?.;,!*:\"/+@#$%^&()"; fontname = "-adobe-courier-bold-r-normal--46-*-100-100-m-*-iso8859-1"; filename = "default.txf"; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-w")) { i++; texw = atoi(argv[i]); } else if (!strcmp(argv[i], "-h")) { i++; texh = atoi(argv[i]); } else if (!strcmp(argv[i], "-gap")) { i++; gap = atoi(argv[i]); } else if (!strcmp(argv[i], "-byte")) { format = TXF_FORMAT_BYTE; break; } else if (!strcmp(argv[i], "-bitmap")) { format = TXF_FORMAT_BITMAP; } else if (!strcmp(argv[i], "-glist")) { i++; glist = (unsigned char *) argv[i]; } else if (!strcmp(argv[i], "-fn")) { i++; fontname = argv[i]; } else if (!strcmp(argv[i], "-file")) { i++; filename = argv[i]; } else { usageError = 1; } } if (usageError) { putchar('\n'); printf("usage: texfontgen [options] txf-file\n"); printf(" -w # textureWidth (def=%d)\n", texw); printf(" -h # textureHeight (def=%d)\n", texh); printf(" -gap # gap between glyphs (def=%d)\n", gap); printf(" -bitmap use a bitmap encoding (default)\n"); printf(" -byte use a byte encoding (less compact)\n"); printf(" -glist ABC glyph list (def=%s)\n", glist); printf(" -fn name X font name (def=%s)\n", fontname); printf(" -file name output file for textured font (def=%s)\n", fontname); putchar('\n'); exit(1); } texarea = calloc(texw * texh, sizeof(unsigned char)); glist = (unsigned char *) nodupstring((char *) glist); dpy = XOpenDisplay(NULL); if (!dpy) { printf("could not open display\n"); exit(1); } /* find an OpenGL-capable RGB visual with depth buffer */ xfont = XLoadQueryFont(dpy, fontname); if (!xfont) { printf("could not get load X font: %s\n", fontname); exit(1); } fontinfo = SuckGlyphsFromServer(dpy, xfont->fid); if (!fontinfo) { printf("could not get font glyphs\n"); exit(1); } len = (int) strlen((char *) glist); qsort(glist, len, sizeof(unsigned char), glyphCompare); file = fopen(filename, "wb"); if (!file) { printf("could not open %s for writing\n", filename); exit(1); } fwrite("\377txf", 1, 4, file); endianness = 0x12345678; /*CONSTANTCONDITION*/ assert(sizeof(int) == 4); /* Ensure external file format size. */ fwrite(&endianness, sizeof(int), 1, file); fwrite(&format, sizeof(int), 1, file); fwrite(&texw, sizeof(int), 1, file); fwrite(&texh, sizeof(int), 1, file); fwrite(&fontinfo->max_ascent, sizeof(int), 1, file); fwrite(&fontinfo->max_descent, sizeof(int), 1, file); fwrite(&len, sizeof(int), 1, file); px = gap; py = gap; maxheight = 0; for (i = 0; i < len; i++) { if (glist[i] != 0) { /* If not already processed... */ /* Try to find a character from the glist that will fit on the remaining space on the current row. */ int foundWidthFit = 0; int c; getMetric(fontinfo, glist[i], &tgi); width = tgi.width; height = tgi.height; if (height > 0 && width > 0) { for (j = i; j < len;) { if (height > 0 && width > 0) { if (px + width + gap < texw) { foundWidthFit = 1; if (j != i) { i--; /* Step back so i loop increment leaves us at same character. */ } break; } } j++; getMetric(fontinfo, glist[j], &tgi); width = tgi.width; height = tgi.height; } /* If a fit was found, use that character; otherwise, advance a line in the texture. */ if (foundWidthFit) { if (height > maxheight) { maxheight = height; } c = j; } else { getMetric(fontinfo, glist[i], &tgi); width = tgi.width; height = tgi.height; py += maxheight + gap; px = gap; maxheight = height; if (py + height + gap >= texh) { printf("Overflowed texture space.\n"); exit(1); } c = i; } /* Place the glyph in the texture image. */ placeGlyph(fontinfo, glist[c], texarea, texw, px, py); /* Assign glyph's texture coordinate. */ tgi.x = px; tgi.y = py; /* Advance by glyph width, remaining in the current line. */ px += width + gap; } else { /* No texture image; assign invalid bogus texture coordinates. */ tgi.x = -1; tgi.y = -1; } glist[c] = 0; /* Mark processed; don't process again. */ /*CONSTANTCONDITION*/ assert(sizeof(tgi) == 12); /* Ensure external file format size. */ fwrite(&tgi, sizeof(tgi), 1, file); } } switch (format) { case TXF_FORMAT_BYTE: fwrite(texarea, texw * texh, 1, file); break; case TXF_FORMAT_BITMAP: stride = (texw + 7) >> 3; texbitmap = (unsigned char *) calloc(stride * texh, 1); for (i = 0; i < texh; i++) { for (j = 0; j < texw; j++) { if (texarea[i * texw + j] >= 128) { texbitmap[i * stride + (j >> 3)] |= 1 << (j & 7); } } } fwrite(texbitmap, stride * texh, 1, file); free(texbitmap); break; default: printf("Unknown texture font format.\n"); exit(1); }
static int test_dlopen() { metric *mdef; cpu_metrics *cpu_rec; memory_metrics *memory_rec; void *dlh; int (*getMetric)(const char *, metric **, metric_context); void (*metricFree)(metric *); memory_metrics *(*memoryMetricsAlloc)(void); void (*memoryMetricsFree)(memory_metrics *); cpu_metrics * (*cpuMetricsAlloc)(void); int (*cpuMetricsFree)(cpu_metrics *); int (*getHostCpuMetrics)(cpu_metrics *); int (*getHostMemoryMetrics)(memory_metrics *); if ((dlh = dlopen("libmetrics.so.0", RTLD_LAZY | RTLD_LOCAL)) == NULL) { fprintf(stderr, "Unable to open dynamic metrics library\n"); exit(1); } /* get the dynamic function pointers */ getMetric = dlsym(dlh, "get_metric"); metricFree = dlsym(dlh, "metric_free"); memoryMetricsAlloc = dlsym(dlh, "memory_metrics_alloc"); memoryMetricsFree = dlsym(dlh, "memory_metrics_free"); cpuMetricsAlloc = dlsym(dlh, "cpu_metrics_alloc"); cpuMetricsFree = dlsym(dlh, "cpu_metrics_free"); getHostCpuMetrics = dlsym(dlh, "get_host_cpu_metrics"); getHostMemoryMetrics = dlsym(dlh, "get_host_memory_metrics"); /* Generic metric get */ if (getMetric("UsedMem", &mdef, METRIC_CONTEXT_HOST) == 0) { uint64_t usedMem = mdef->value.ui64; fprintf(stderr, "UsedMem: %"PRIu64"\n", usedMem); } else { fprintf(stderr, "UsedMem: metric not found\n"); } metricFree(mdef); if (getMetric("TotalCPUTime", &mdef, METRIC_CONTEXT_HOST) == 0) { double cpu_time = mdef->value.r64; fprintf(stderr, "TotalCPUTime: %f\n", cpu_time); } else { fprintf(stderr, "TotalCPUTime: metric not found\n"); } metricFree(mdef); if (getMetric("TotalCPUTime", &mdef, METRIC_CONTEXT_VM) == 0) { double cpu_time = mdef->value.r64; fprintf(stderr, "VM TotalCPUTime: %f\n", cpu_time); } else { fprintf(stderr, "Indv VM TotalCPUTime: metric not found\n"); } metricFree(mdef); /* Class metrics get, host cpu */ cpu_rec = cpuMetricsAlloc(); if (getHostCpuMetrics(cpu_rec) == 0) { fprintf(stderr, "Class Host CPU\n"); fprintf(stderr, "\t total_phys_cpus: %d\n", cpu_rec->total_phys_cpus); fprintf(stderr, "\t num_phys_cpus_utilized: %d\n", cpu_rec->num_phys_cpus_utilized); fprintf(stderr, "\t total_cpu_time: %lf\n", cpu_rec->total_cpu_time); } cpuMetricsFree(cpu_rec); /* Class metrics get, host memory */ memory_rec = memoryMetricsAlloc(); if (getHostMemoryMetrics(memory_rec) == 0) { fprintf(stderr, "Class Host Memory \n"); fprintf(stderr, "\t total_physical_memory: %"PRIu64"\n", memory_rec->total_physical_memory); fprintf(stderr, "\t used_physical_memory: %"PRIu64"n", memory_rec->used_physical_memory); fprintf(stderr, "\t free_physical_memory: %"PRIu64"\n", memory_rec->free_physical_memory); fprintf(stderr, "\t paged_in_memory: %"PRIu64"\n", memory_rec->paged_in_memory); fprintf(stderr, "\t paged_out_memory: %"PRIu64"\n", memory_rec->paged_out_memory); fprintf(stderr, "\t page_in_rate: %"PRIu64"\n", memory_rec->page_in_rate); fprintf(stderr, "\t paged_fault_rate: %"PRIu64"\n", memory_rec->page_fault_rate); } memoryMetricsFree(memory_rec); dlclose(dlh); return 0; }
Mahalanobis InfTheoMetricLearner::learnMetric() { computeConstraints(); int dim = getVectorDim(); Mahalanobis metric = getMetric(); metric.setM(M0); int simConCount = simConstraints.getConstraintCount(); int disSimConCount = disSimConstraints.getConstraintCount(); vec x1; vec x2; double slack = 0.0; double lambda = 0.0; InfTheoConstraints* currentConstSet = NULL; int currentIdx = 0; int currentSimIdx = 0; int currentDisSimIdx = 0; double p = 0.0; double delta = 0.0; double alpha = 0.0; double beta = 0.0; int i = 0; for(i = 0; !checkConvergence(metric.getM()) && (simConCount || disSimConCount); ++i) { // choose sim constraint if(i % 2 && simConCount) { currentConstSet = &simConstraints; currentIdx = currentSimIdx = (currentSimIdx + 1) % simConCount; // line 3.3 delta = 1; } // choose dissim constraint else if(!(i %2) && disSimConCount) { currentConstSet = &disSimConstraints; currentIdx = currentDisSimIdx = (currentDisSimIdx + 1) % disSimConCount; // line 3.3 delta = -1; } // pick some constraint (line 3.1) x1 = currentConstSet->getX1(currentIdx); x2 = currentConstSet->getX2(currentIdx); slack = currentConstSet->getSlack(currentIdx); lambda = currentConstSet->getLambda(currentIdx); // line 3.2 p = metric.computeSquaredDistance(x1, x2); // ignore pairs with x1 == x2 if(p > 0) { // line 3.4 alpha = min(lambda, delta / 2.0 * (1.0 / p - gamma / slack)); // line 3.5 beta = delta * alpha / (1.0 - delta * alpha * p); /* // prints debug information cout << "p: " << p << endl; cout << "alpha: " << alpha << endl; cout << "1.0 / p: " << (1.0 / p) << endl; cout << "gamma / slack: " << (gamma / slack) << endl; cout << x1.t() << endl << x2.t() << endl; cout << "delta / 2.0 * (1.0 / p - gamma / slack): " << (delta / 2.0 * (1.0 / p - gamma / slack)) << endl; cout << "beta: " << beta << endl; */ // line 3.6 double nextSlack = gamma * slack / (gamma + delta * alpha * slack); currentConstSet->setSlack(currentIdx, nextSlack); // line 3.7 double nextLambda = lambda - alpha; currentConstSet->setLambda(currentIdx, nextLambda); // line 3.8 mat currentM = metric.getM(); currentM = currentM + beta * currentM * (x1 - x2) * (x1 - x2).t() * currentM; metric.setM(currentM); } } cout << "(InfTheoMetricLearner) metric learning converged in " << i << " iterations" << endl; return metric; }
void Route4::printAll(std::ostream & os) const { Addr4::printAll(os); os << "Metric: " << getMetric() << std::endl; }
bool compare_greater(const HeapItem& i) const { PrintHelperHeapItem other_heap_item = static_cast<const PrintHelperHeapItem&>(i); return getMetric() > other_heap_item.getMetric(); }