From e313008ad0c5ce583ec42a6e03bdb41ca4156781 Mon Sep 17 00:00:00 2001 From: zark721 Date: Tue, 28 Nov 2023 13:50:43 +0800 Subject: [PATCH] 1. delete unnecessary buffer stream. 2. fix minor problem when aggregate vertex. --- .../edu/cmu/graphchi/shards/MemoryShard.java | 24 +++++++------------ .../graphchi/vertexdata/VertexAggregator.java | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main/java/edu/cmu/graphchi/shards/MemoryShard.java b/src/main/java/edu/cmu/graphchi/shards/MemoryShard.java index b183dfa3..1f38eefc 100644 --- a/src/main/java/edu/cmu/graphchi/shards/MemoryShard.java +++ b/src/main/java/edu/cmu/graphchi/shards/MemoryShard.java @@ -285,7 +285,7 @@ private void loadAdjChunk(int windowStart, int windowEnd, ChiVertex[] vertices, } - private DataInput loadAdj() throws FileNotFoundException, IOException { + private DataInput loadAdj() throws IOException { File compressedFile = new File(adjDataFilename + ".gz"); InputStream adjStreamRaw; long fileSizeEstimate = 0; @@ -300,31 +300,25 @@ private DataInput loadAdj() throws FileNotFoundException, IOException { /* Load index */ index = new ShardIndex(new File(adjDataFilename)).sparserIndex(1204 * 1024); - BufferedInputStream adjStream = new BufferedInputStream(adjStreamRaw, (int) fileSizeEstimate / - 4); - + byte[] buf = new byte[(int)fileSizeEstimate]; // Hack for cases when the load is not divided into subwindows TimerContext _timer = loadAdjTimer.time(); - ByteArrayOutputStream adjDataStream = new ByteArrayOutputStream((int) fileSizeEstimate); try { - byte[] buf = new byte[(int) fileSizeEstimate / 4]; // Read in 16 chunks - while (true) { - int read = adjStream.read(buf); - if (read > 0) { - adjDataStream.write(buf, 0, read); - } else break; + int nread = adjStreamRaw.read(buf, 0, buf.length); + if (nread < buf.length) { + // compressed + byte[] buf2 = new byte[nread]; + System.arraycopy(buf, 0, buf2, 0, nread); + buf = buf2; } } catch (EOFException err) { // Done } - adjData = adjDataStream.toByteArray(); + adjData = buf; adjDataLength = adjData.length; - adjStream.close(); - adjDataStream.close(); - _timer.stop(); return null; } diff --git a/src/main/java/edu/cmu/graphchi/vertexdata/VertexAggregator.java b/src/main/java/edu/cmu/graphchi/vertexdata/VertexAggregator.java index 933a968b..7996ea97 100644 --- a/src/main/java/edu/cmu/graphchi/vertexdata/VertexAggregator.java +++ b/src/main/java/edu/cmu/graphchi/vertexdata/VertexAggregator.java @@ -55,7 +55,7 @@ public static void foreach(int numVertices, String baseFilename int CHUNK = 1000000; for(int i=0; i < numVertices; i += CHUNK) { - int en = i + CHUNK; + int en = i + CHUNK - 1; if (en >= numVertices) en = numVertices - 1; int blockId = vertexData.load(i, en);