std::vector<SubGraph> FilterMutualInfoPlugin::CreateGraphs(MeshDocument &md, std::vector<AlignPair> arcs) { std::vector<SubGraph> Gr; SubGraph allNodes; int numNodes=md.rasterList.size(); Log(0, "Tuttok1"); for (int s=0; s<numNodes; s++) { Node n; n.active=false; n.assigned=false; n.grNum=0; n.avMut=0.0; allNodes.nodes.push_back(n); } int totGr=1; bool done=false; std::vector<int> nod; for (int i=0; i<arcs.size(); i++) { int cand=arcs[i].imageId; bool insert=true; for (int j=0; j<nod.size(); j++) { if(nod[j]==cand) { insert=false; break; } } if(insert) nod.push_back(cand); int cand2=arcs[i].projId; insert=true; for (int j=0; j<nod.size(); j++) { if(nod[j]==cand2) { insert=false; break; } } if(insert) nod.push_back(cand2); } int involvedNodes=nod.size(); int totNodes=0; Log(0, "Tuttok2"); while (!done) { for (int i=0; i<arcs.size(); i++) { int candidate=arcs[i].imageId; if(allNodes.nodes[candidate].assigned==false) { allNodes.nodes[candidate].assigned=true; allNodes.nodes[candidate].grNum=totGr; totNodes++; for (int j=0; j<arcs.size(); j++) { if (arcs[j].imageId==candidate) { if (allNodes.nodes[arcs[j].projId].assigned==false) { allNodes.nodes[arcs[j].projId].assigned=true; allNodes.nodes[arcs[j].projId].grNum=totGr; totNodes++; } } } } } if (totNodes==involvedNodes) done=true; else totGr++; } Log(0, "Tuttok3"); for (int i=1; i<totGr+1; i++) { SubGraph graph; graph.id=i; for (int j=0; j<numNodes; j++) { Log(0, "Node %d of %d",j,numNodes); if (allNodes.nodes[j].grNum==i) { Node n; double mut=0.0; double are=0.00001; if(md.rasterList[j]->visible) n.active=false; else n.active=true; n.id=j; n.avMut=0.0; for (int k=0; k<arcs.size(); k++) { if(arcs[k].imageId==j) { n.avMut+=arcs[k].weight; n.arcs.push_back(arcs[k]); } } std::sort(n.arcs.begin(), n.arcs.end(), ordering()); graph.nodes.push_back(n); Log(0, "Node %d of %d: avMut %3.2f, arch %d",j,numNodes, n.avMut, n.arcs.size()); } else { Node n; n.active=true; n.id=j; n.avMut=0.0; graph.nodes.push_back(n); Log(0, "Node %d of %d: not used",j,numNodes); } } Gr.push_back(graph); } Log(0, "Tuttok5"); Log(0, "Tot nodes %d, SubGraphs %d",numNodes,totGr); return Gr; }
void PinDialog::accept() { if (!check_edits(edits) || !kvtable->check_unique()) return; BrowserNode * bn = pin->browser_node; QString s; s = edname->text().trimmed(); if ((s != pin->name()) && ((BrowserNode *) bn->parent())->wrong_child_name(s, UmlActivityPin, bn->allow_spaces(), bn->allow_empty())) msg_critical(tr("Error"), s + tr("\n\nillegal name or already used")); else { // check consistency UmlParamDirection dir = direction(eddir->currentText().toLatin1().constData()); bool exception = exception_rb->isChecked(); UmlParamEffect effect = ::effect(edeffect->currentText().toLatin1().constData()); QString err; if ((dir == UmlIn) && exception) err = tr("An input pin cannot be an exception.\n"); switch (effect) { case UmlDelete: if ((dir != UmlIn) && (dir != UmlInOut)) err += tr("Only in and inout pin may have a delete effect."); break; case UmlCreate: if ((dir != UmlOut) && (dir != UmlInOut) && (dir != UmlReturn)) err += tr("Only out, inout and return pin may have a create effect."); break; default: break; } if (!err.isEmpty()) msg_critical(tr("Error"), err); else { bn->set_name(s); bool newst = pin->set_stereotype(fromUnicode(edstereotype->currentText().trimmed())); AType t; s = edtype->currentText().trimmed(); if (!s.isEmpty()) { int index = list.indexOf(s); if (index >= 0) t.type = (BrowserClass *) nodes.at(index); else t.explicit_type = s; } pin->set_type(t); pin->dir = dir; pin->multiplicity = edmultiplicity->currentText().trimmed(); pin->ordering = ordering(edordering->currentText().toLatin1().constData()); pin->effect = effect; pin->is_control = is_control_cb->isChecked(); pin->unique = unique_cb->isChecked(); pin->in_state = edin_state->text().trimmed(); pin->exception = exception; pin->stream = stream_rb->isChecked(); pin->uml_selection = eduml_selection->text().trimmed(); pin->cpp_selection = edcpp_selection->text().trimmed(); pin->java_selection = edjava_selection->text().trimmed(); bn->set_comment(comment->text()); UmlWindow::update_comment_if_needed(bn); kvtable->updateNodeFromThis(bn); ProfiledStereotypes::modified(bn, newst); bn->modified(); bn->package_modified(); pin->modified(); TabDialog::accept(); } } }
int ORD::find_elim_ordering() { int ws; int wr; char eoname[512]; char eoname_other[512]; // Get size and rank from the communicator MPI_Comm_size(comm, &ws); MPI_Comm_rank(comm, &wr); double xtime = MPI_Wtime(); sprintf(eoname, "%s.order.%d", this->filename.c_str(), ws); sprintf(eoname_other, "%s.order_other.%d", this->filename.c_str(), ws); DEBUG("size: %d, rank %d \n", ws, wr); int n = G->get_num_nodes(); int x = n/ws; int xm = n%ws; int i = 0; DEBUG("n: %d x: %d xm: %d \n", n, x, xm); vector<int> xadj; vector<int> adjncy; vector<int> vtxdist(ws + 1, 0); vector<int> sizes(2*ws,0); vector<int> ordering(x+1, 0); vector<int> recvcnt(ws, 0); vector<int> displ(ws, 0); int numflag = 0; int options[10]; options[0] = 0; vtxdist[0] = 0; for (i = 1; i <= ws; i++) { vtxdist[i] = vtxdist[i - 1] + x; if (i <= xm) vtxdist[i]++; } // prepareing displacement and receive counts to use with MPI_Gatherv for (i = 0; i < ws; i++) { recvcnt[i] = x; if (i < xm) recvcnt[i] ++; if (i > 0) displ[i] += displ[i - 1] + recvcnt[i - 1]; } DEBUG("range: %d, %d\n", vtxdist[wr], vtxdist[wr + 1]); int j = 0; xadj.push_back(0); for (i = vtxdist[wr]; i < vtxdist[wr + 1]; i++) { Graph::Node *no = G->get_node(i); list<int> *l = no->get_nbrs_ptr(); list<int>::iterator it = l->begin(); for (; it != l->end(); ++it) { adjncy.push_back(*it); j++; } xadj.push_back(j); } if (METIS_OK != ParMETIS_V3_NodeND(&vtxdist.front(), &xadj.front(), &adjncy.front(), &numflag, options, &ordering.front(), &sizes.front(), &comm)) { FERROR("error occured while processing parmetis, aborting\n"); MPI_Abort(MPI_COMM_WORLD, -1); } DEBUG("output from ParMETIS\n"); double parmet_time = MPI_Wtime() - xtime; vector<int> recvbuf; n = G->get_num_nodes(); if (wr == 0) { recvbuf = vector<int>(n, 0); } if (MPI_SUCCESS != MPI_Gatherv((void *)&ordering.front(), recvcnt[wr], MPI_INT, (void *)&recvbuf.front(), &recvcnt.front(), &displ.front(), MPI_INT, 0, comm)) { FERROR("MPI error occured at Gatherv, Abort!\n"); MPI_Abort(comm, -1); } vector<int> eo(n, 0); if (wr == 0) { for (int i = 0; i < n; i++) { eo[recvbuf[i]] = i; } FILE *f = fopen(eoname_other, "w"); for (int i = 0; i < n; i++) fprintf(f, "%d\n", eo[i] + 1); fclose(f); DEBUG("ParMetis NodeND elimination ordering is in : %s\n", eoname_other); } ordering.clear(); ordering.resize(recvcnt[wr], 0); if (MPI_SUCCESS != MPI_Scatterv ((void *)&eo.front(), &recvcnt.front(), &displ.front(), MPI_INT, (void *)&ordering.front(), recvcnt[wr], MPI_INT, 0, comm)) { FERROR("MPI error occured at Scatterv, Abort! \n"); MPI_Abort(comm, -1); } DEBUG("Scatterv completed\n"); Graph::GraphCreatorFile gf; Graph::WeightedMutableGraph *wg; Graph::GraphEOUtil eoutil; Graph::GraphProperties prop; list<int>members(ordering.begin(), ordering.end()); wg = gf.create_component(G, &members, false); prop.make_canonical(wg); vector<int> ord(recvcnt[wr], 0); vector<int> ordsend(recvcnt[wr, 0]); double xxtime = MPI_Wtime(); eoutil.find_elimination_ordering(wg, &ord, GD_AMD, false); DEBUG("eo time : %f\n", MPI_Wtime() - xxtime); int sz = recvcnt[wr]; for (int i = 0; i < sz; i++) ordsend[i] = wg->get_node(ord[i])->get_label(); recvbuf.assign(n, -1); if (MPI_SUCCESS != MPI_Gatherv((void *)&ordsend.front(), recvcnt[wr], MPI_INT, (void *)&recvbuf.front(), &recvcnt.front(), &displ.front(), MPI_INT, 0, comm)) { FERROR("MPI error occured at Gatherv, Abort!\n"); MPI_Abort(comm, -1); } double p_amd_time = MPI_Wtime() - xtime; if (wr == 0) { FILE *f = fopen(eoname, "w"); for (int i = 0; i < n && wr == 0; i++) fprintf(f, "%d\n", recvbuf[i]); fclose(f); } DEBUG("ordering is written into %s\n", eoname); DEBUG("%f,%f\n", parmet_time, p_amd_time); return 0; }