Package com.intel.hadoop.graphbuilder.util

Examples of com.intel.hadoop.graphbuilder.util.Parallel


      list.add(new MutableInt(rnd.nextInt()));

    ArrayList<MutableInt> copylist = new ArrayList<MutableInt>();
    for (int i = 0; i < maxiter; ++i)
      copylist.add(new MutableInt(list.get(i).val));
    Parallel parfor = new Parallel();
    parfor.For(list, new Operation<MutableInt>() {
      @Override
      public void perform(MutableInt pParameter, int idx) {
        pParameter.val += idx;
      }

    });
    parfor.close();

    for (int i = 0; i < maxiter; ++i) {
      int j = list.get(i).val;
      int k = copylist.get(i).val + i;
      assertEquals(j, k);
View Full Code Here


    final ArrayList<AtomicInteger> counterArray2 = new ArrayList<AtomicInteger>(
        maxint);
    for (int i = 0; i < maxint; ++i)
      counterArray2.add(new AtomicInteger(0));

    Parallel parfor = new Parallel();
    parfor.For(toSort, new Operation<Integer>() {
      @Override
      public void perform(Integer p, int idx) {
        counterArray.get(p).incrementAndGet();
      }
    });
    parfor.close();

    for (int i = 0; i < toSort.size(); ++i) {
      counterArray2.get(toSort.get(i)).incrementAndGet();
    }
View Full Code Here

  public void finalize() throws Exception {
    if (finalized)
      return;

    boolean parallel = true;
    Parallel parfor = new Parallel();

    LOG.debug("Finalize graph of size: " + edgeInfo.size());
    ArrayList<Integer> permute = new ArrayList<Integer>(Collections.nCopies(
        numEdges, 0));
    ArrayList<AtomicInteger> counterArray = new ArrayList<AtomicInteger>(
        numVertices + 1);
    for (int j = 0; j < numVertices + 1; ++j)
      counterArray.add(new AtomicInteger(0));

    /* Construct the CSR */
    /* Sort and divide edges by source id using counting sort. */
    LOG.debug("Coutning sort source...");
    counting_sort(edgeInfo.sources, counterArray, permute);
    final CompareByVid cmpByTarget = new CompareByVid(edgeInfo.targets);

    final ArrayList<List<Integer>> dummyList = new ArrayList<List<Integer>>(
        numVertices);
    /* Sort each part (of the same source) by its target. */
    if (parallel) {
      LOG.debug("Parallel sort target within source...");
      for (int j = 0; j < numVertices; ++j)
        dummyList.add(permute.subList(counterArray.get(j).get(), counterArray
            .get(j + 1).get()));
      parfor.For(dummyList, new Operation<List<Integer>>() {
        @Override
        public void perform(List<Integer> pParameter, int idx) {
          // TODO Auto-generated method stub
          java.util.Collections.sort(pParameter, cmpByTarget);
        }
      });
    } else {
      for (int j = 0; j < numVertices; ++j) {
        java.util.Collections.sort(permute.subList(counterArray.get(j).get(),
            counterArray.get(j + 1).get()), cmpByTarget);
      }
    }

    /*
     * Shuffle in place the sources, targets, and edatalist using the permute
     * index.
     */
    edgeInfo.inplace_shuffle(permute);

    /* Fill in the CSR data structure. */
    csr = new SparseGraphStruct(numVertices, edgeInfo.sources, edgeInfo.targets);

    /* Construct the CSC */
    /* Sort and divide edges by source id using counting sort. */
    LOG.debug("Coutning sort target...");
    counting_sort(edgeInfo.targets, counterArray, permute);
    final CompareByVid cmpBySource = new CompareByVid(edgeInfo.sources);
    if (parallel) {
      LOG.debug("Parallel sort source within target...");
      dummyList.clear();
      for (int j = 0; j < numVertices; ++j)
        dummyList.add(permute.subList(counterArray.get(j).get(), counterArray
            .get(j + 1).get()));
      parfor.For(dummyList, new Operation<List<Integer>>() {
        @Override
        public void perform(List<Integer> pParameter, int idx) {
          java.util.Collections.sort(pParameter, cmpBySource);
        }
      });
    } else {
      for (int j = 0; j < numVertices; ++j) {
        java.util.Collections.sort(permute.subList(counterArray.get(j).get(),
            counterArray.get(j + 1).get()), cmpBySource);
      }
    }

    /* Shuffle out of place the sources. */
    final ArrayList<Integer> shuffledSource = new ArrayList<Integer>(
        Collections.nCopies(edgeInfo.sources.size(), 0));

    parfor.For(permute, new Operation<Integer>() {
      @Override
      public void perform(Integer val, int idx) {
        shuffledSource.set(idx, edgeInfo.sources.get(val));
      }
    });

    edgeInfo.sources = shuffledSource;

    // Fill in the CSC data structure
    List<Integer> transformedTargets = new ArrayList<Integer>(
        edgeInfo.targets.size());
    for (int j = 0; j < edgeInfo.targets.size(); ++j) {
      transformedTargets.add(edgeInfo.targets.get(permute.get(j)));
    }
    csc = new SparseGraphStruct(numVertices, transformedTargets,
        edgeInfo.sources);

    c2rMap = permute;
    edatalist = edgeInfo.edata;
    finalized = true;
    parfor.close();
  }
View Full Code Here

  private <valueType> void counting_sort(ArrayList<valueType> valueArray,
      final ArrayList<AtomicInteger> counterArray,
      final ArrayList<Integer> permute) {

    assert permute.size() == valueArray.size();
    Parallel parfor = new Parallel();
    for (int j = 0; j < counterArray.size(); j++)
      counterArray.get(j).set(0);

    for (int j = 0; j < permute.size(); j++)
      permute.set(j, 0);

    parfor.For(valueArray, new Operation<valueType>() {
      @Override
      public void perform(valueType val, int idx) {
        counterArray.get((Integer) val).incrementAndGet();
      }

    });

    for (int j = 1; j < counterArray.size(); j++)
      counterArray.get(j).addAndGet(counterArray.get(j - 1).get());

    parfor.For(valueArray, new Operation<valueType>() {
      @Override
      public void perform(valueType val, int idx) {
        permute.set(counterArray.get((Integer) val).decrementAndGet(), idx);
      }

    });

    parfor.close();
  }
View Full Code Here

TOP

Related Classes of com.intel.hadoop.graphbuilder.util.Parallel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.