void operator()(GNode item, Galois::UserContext<GNode>& ctx) {
    if (!graph->containsNode(item, Galois::ALL))
      return;
    
    Cavity* cavp = NULL;

    if (Version == detDisjoint) {
      bool used;
      LocalState* localState = (LocalState*) ctx.getLocalState(used);
      if (used) {
        localState->cav.update(item, ctx);
        return;
      } else {
        cavp = &localState->cav;
      }
    }

    if (Version == detDisjoint) {
      cavp->initialize(item);
      cavp->build();
      cavp->computePost();
    } else {
      Cavity cav(graph, ctx.getPerIterAlloc());
      cav.initialize(item);
      cav.build();
      cav.computePost();
      if (Version == detPrefix)
        return;
      cav.update(item, ctx);
    }
  }
示例#2
0
  /**
   * Do reverse BFS on residual graph.
   */
  void operator()(const GNode& src, Galois::UserContext<GNode>& ctx) {
    if (version != nondet) {
      bool used = false;
      if (version == detDisjoint) {
        ctx.getLocalState(used);
      }

      if (!used) {
        for (Graph::edge_iterator
            ii = app.graph.edge_begin(src, Galois::CHECK_CONFLICT),
            ee = app.graph.edge_end(src, Galois::CHECK_CONFLICT);
            ii != ee; ++ii) {
          GNode dst = app.graph.getEdgeDst(ii);
          int rdata = app.graph.getEdgeData(findEdge(app.graph, dst, src));
          if (rdata > 0) {
            app.graph.getData(dst, Galois::CHECK_CONFLICT);
          }
        }
      }

      if (version == detDisjoint) {
        if (!used)
          return;
      } else {
        app.graph.getData(src, Galois::WRITE);
      }
    }

    for (Graph::edge_iterator
        ii = app.graph.edge_begin(src, useCAS ? Galois::NONE : Galois::CHECK_CONFLICT),
        ee = app.graph.edge_end(src, useCAS ? Galois::NONE : Galois::CHECK_CONFLICT);
        ii != ee; ++ii) {
      GNode dst = app.graph.getEdgeDst(ii);
      int rdata = app.graph.getEdgeData(findEdge(app.graph, dst, src));
      if (rdata > 0) {
        Node& node = app.graph.getData(dst, Galois::NONE);
        int newHeight = app.graph.getData(src, Galois::NONE).height + 1;
        if (useCAS) {
          int oldHeight;
          while (newHeight < (oldHeight = node.height)) {
            if (__sync_bool_compare_and_swap(&node.height, oldHeight, newHeight)) {
              ctx.push(dst);
              break;
            }
          }
        } else {
          if (newHeight < node.height) {
            node.height = newHeight;
            ctx.push(dst);
          }
        }
      }
    }
  }
示例#3
0
  void operator()(UpdateRequest& req, Galois::UserContext<UpdateRequest>& ctx) const {
    Galois::MethodFlag flag = useCas ? Galois::NONE : Galois::ALL;
    SNode& data = graph.getData(req.n, flag);

    if (trackBadWork && req.w > data.dist) {
      *WLEmptyWork += 1;
      return;
    }
    
    for (Graph::edge_iterator ii = graph.edge_begin(req.n, flag),
           ee = graph.edge_end(req.n, flag); ii != ee; ++ii) {
      GNode dst = graph.getEdgeDst(ii);
      unsigned int d = graph.getEdgeData(ii);
      SNode& rdata = graph.getData(dst, Galois::NONE);
      unsigned int newDist = data.dist + d;
      unsigned int v;
      while (newDist < (v = rdata.dist)) {
        if (!useCas || __sync_bool_compare_and_swap(&rdata.dist, v, newDist)) {
          if (!useCas)
            rdata.dist = newDist;
          if (trackBadWork && v != DIST_INFINITY)
             *BadWork += 1;
          ctx.push(UpdateRequest(dst, newDist));
          break;
        }
      }
    }
  }
示例#4
0
void relax_edge(unsigned src_data, Graph::edge_iterator ii, 
		Galois::UserContext<UpdateRequest>& ctx) {
  GNode dst = graph.getEdgeDst(ii);
  unsigned int edge_data = graph.getEdgeData(ii);
  unsigned& dst_data = graph.getData(dst);
  unsigned int newDist = dst_data + edge_data;
  if (newDist < dst_data) {
    dst_data = newDist;
    ctx.push(std::make_pair(newDist, dst));
  }
}
示例#5
0
void relax_edge(Node src_data, Graph::edge_iterator ii,
                Galois::UserContext<UpdateRequest>& ctx) {
    GNode dst = graph.getEdgeDst(ii);
    unsigned int edge_data = graph.getEdgeData(ii);
    Node& dst_data = graph.getData(dst);
    long long newDist = src_data.distance + edge_data;
    if (newDist < dst_data.distance) {
        Node t(src_data.nodeId, newDist, src_data.path);
        ctx.push(std::make_pair(t, dst));
    }
}
示例#6
0
 void operator()(GNode src, Galois::UserContext<GNode>& ctx) {
   for (Graph::edge_iterator ii = graph.edge_begin(src, Galois::ALL),
       ei = graph.edge_end(src, Galois::ALL); ii != ei; ++ii) {
     GNode dst = graph.getEdgeDst(ii);
     Node& ddata = graph.getData(dst, Galois::NONE);
     if (ddata.component == root)
       continue;
     ddata.component = root;
     mst.push(std::make_pair(src, dst));
     ctx.push(dst);
   }
 }
 void operator()(GNode node, Galois::UserContext<GNode> &lwl) { 
   auto flag = Galois::NONE;
   Node &nData = graph.getData(node);
   for (Graph::edge_iterator ei = graph.edge_begin(node,flag),ee=graph.edge_end(node,flag);
     ei != ee; ei++) {
     GNode neigh = graph.getEdgeDst(ei);
     Node &neighData = graph.getData(neigh,Galois::WRITE);
     if (neighData.component > nData.component) {
       neighData.component = nData.component;
       lwl.push(neigh);
     }
   }
 }
示例#8
0
  void operator()(GNode& src, Galois::UserContext<GNode>& ctx) {
    int increment = 1;
    acquire(src);
    if (discharge(src, ctx)) {
      increment += BETA;
    }

    int v = *counter.local.getLocal() += increment;
    if (app.global_relabel_interval > 0 && v >= limit) {
      app.should_global_relabel = true;
      ctx.breakLoop();
      return;
    }
  }
	void operator()(GNode& n, Galois::UserContext<GNode>& ctx) const {
		//std::cout << Galois::getActiveThreads() << std::endl;
		SNode& data = graph.getData(n, Galois::NONE);

		unsigned int newDist = data.dist;

		for (Graph::edge_iterator ii = graph.edge_begin(n, Galois::NONE),
				ei = graph.edge_end(n, Galois::NONE); ii != ei; ++ii) {
			GNode dst = graph.getEdgeDst(ii);
			SNode& ddata = graph.getData(dst, Galois::NONE);
			if(ddata.dist > newDist){
				graph.getData(dst, Galois::NONE).dist= newDist;
				ctx.push(dst);
			}
		}
	}
示例#10
0
  void operator()(UpdateRequest& req, Galois::UserContext<UpdateRequest>& lwl) {
    SNode& data = graph.getData(req.n,Galois::NONE);
    // if (req.w >= data.dist)
    //   *WLEmptyWork += 1;
    unsigned int v;
    while (req.w < (v = data.dist[req.c])) {
      if (__sync_bool_compare_and_swap(&data.dist[req.c], v, req.w)) {
	// if (v != DIST_INFINITY)
	//   *BadWork += 1;
	for (Graph::edge_iterator ii = graph.edge_begin(req.n, Galois::NONE),
	       ee = graph.edge_end(req.n, Galois::NONE); ii != ee; ++ii) {
	  GNode dst = graph.getEdgeDst(ii);
	  int d = graph.getEdgeData(ii);
	  unsigned int newDist = req.w + d;
	  SNode& rdata = graph.getData(dst,Galois::NONE);
	  if (newDist < rdata.dist[req.c])
	    lwl.push(UpdateRequest(dst, newDist, req.c));
	}
	break;
      }
    }
  }
示例#11
0
  void operator()(GNode& src, Galois::UserContext<GNode>& ctx) {
    if (version != nondet) {
      bool used = false;
      if (version == detDisjoint) {
        ctx.getLocalState(used);
      }
      if (!used) {
        acquire(src);
      }
      if (version == detDisjoint) {
        if (!used)
          return;
      } else {
        app.graph.getData(src, Galois::WRITE);
      }
    }

    int increment = 1;
    if (discharge(src, ctx)) {
      increment += BETA;
    }

    counter.accum += increment;
  }
示例#12
0
bool discharge(const GNode& src, Galois::UserContext<GNode>& ctx) {
  //Node& node = app.graph.getData(src, Galois::CHECK_CONFLICT);
  Node& node = app.graph.getData(src, Galois::NONE);
  //int prevHeight = node.height;
  bool relabeled = false;

  if (node.excess == 0 || node.height >= (int) app.graph.size()) {
    return false;
  }

  while (true) {
    //Galois::MethodFlag flag = relabeled ? Galois::NONE : Galois::CHECK_CONFLICT;
    Galois::MethodFlag flag = Galois::NONE;
    bool finished = false;
    int current = node.current;
    Graph::edge_iterator
      ii = app.graph.edge_begin(src, flag),
      ee = app.graph.edge_end(src, flag);
    std::advance(ii, node.current);
    for (; ii != ee; ++ii, ++current) {
      GNode dst = app.graph.getEdgeDst(ii);
      int cap = app.graph.getEdgeData(ii);
      if (cap == 0)// || current < node.current) 
        continue;

      Node& dnode = app.graph.getData(dst, Galois::NONE);
      if (node.height - 1 != dnode.height) 
        continue;

      // Push flow
      int amount = std::min(static_cast<int>(node.excess), cap);
      reduceCapacity(ii, src, dst, amount);

      // Only add once
      if (dst != app.sink && dst != app.source && dnode.excess == 0) 
        ctx.push(dst);
      
      node.excess -= amount;
      dnode.excess += amount;
      
      if (node.excess == 0) {
        finished = true;
        node.current = current;
        break;
      }
    }

    if (finished)
      break;

    relabel(src);
    relabeled = true;

    if (node.height == (int) app.graph.size())
      break;

    //prevHeight = node.height;
  }

  return relabeled;
}
示例#13
0
 void operator()(int item, Galois::UserContext<int>& lwl) {
   for (int i = 0; i < item; ++i)
     lwl.push(item - 1);
 }