computer science 320 slicing and dicing data with buffers

14
Computer Science 320 Slicing and Dicing Data with Buffers

Upload: jane-hampton

Post on 23-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Science 320 Slicing and Dicing Data with Buffers

Computer Science 320

Slicing and Dicing Data with Buffers

Page 2: Computer Science 320 Slicing and Dicing Data with Buffers

Type-Specific Buffer Classes

• edu.rit.BooleanBuf• edu.rit.ByteBuf• edu.rit.CharacterBuf• edu.rit.DoubleBuf• edu.rit.FloatBuf• edu.rit.IntegerBuf• edu.rit.LongBuf• edu.rit.ShortBuf• edu.rit.ObjectBuf

These are wrappers for primitive values or objects

They all implement Serializable

Page 3: Computer Science 320 Slicing and Dicing Data with Buffers

Example: A Single Item Integer Buffer

IntegerItemBuf buf = IntegerBuf.buffer();

buf.item = 42;

System.out.println(buf.item);

Page 4: Computer Science 320 Slicing and Dicing Data with Buffers

Example: An Integer Array Buffer

int[] data = new int[8];

IntegerBuf buf = IntegerBuf.buffer(data);

Page 5: Computer Science 320 Slicing and Dicing Data with Buffers

Example: An Array Slice

int[] data = new int[8];

Range sliceRange = new Range(2, 4);

IntegerBuf buf = IntegerBuf.buffer(data, sliceRange);

Page 6: Computer Science 320 Slicing and Dicing Data with Buffers

Example: Range Stride > 1

int[] data = new int[8];

Range evenRange = new Range(0, 6, 2);

IntegerBuf buf = IntegerBuf.buffer(data, evenRange);

Page 7: Computer Science 320 Slicing and Dicing Data with Buffers

Example: Partitioning an Array

int[] data = new int[8];

Range[] sliceRanges = new Range(0, 7).subranges(4);

IntegerBuf[] sliceBufs = IntegerBuf.sliceBuffers(data, sliceRanges);

Page 8: Computer Science 320 Slicing and Dicing Data with Buffers

Example: An Integer Matrix Buffer

int[] data = new int[4][8];

IntegerBuf buf = IntegerBuf.buffer(data);

Data are written to and read from the communication buffer in row-major order

Page 9: Computer Science 320 Slicing and Dicing Data with Buffers

Example: A Matrix Row Slice

int[] data = new int[4][8];

Range rowRange = new Range(2, 3);

IntegerBuf buf = IntegerBuf.rowSliceBuffer(data, rowRange);

Only the data values in the row range are transferred through the buffer

Page 10: Computer Science 320 Slicing and Dicing Data with Buffers

Example: A Matrix Column Slice

int[] data = new int[4][8];

Range colRange = new Range(2, 4);

IntegerBuf buf = IntegerBuf.colSliceBuffer(data, colRange);

Only the data values in the column range are transferred through the buffer

Page 11: Computer Science 320 Slicing and Dicing Data with Buffers

Example: A Matrix Patch (Rows and Columns)

int[] data = new int[4][8];

Range rowRange = new Range(1, 2);

Range colRange = new Range(4, 5);

IntegerBuf buf = IntegerBuf.patchBuffer(data, colRange);

Only the data values in the matrix “patch” are transferred through the buffer

Page 12: Computer Science 320 Slicing and Dicing Data with Buffers

Example: Matrix Partition by Rows

int[] data = new int[4][8];

Range[] rowRanges = new Range(0, 3).subranges(4);

IntegerBuf rowBufs = IntegerBuf.rowSliceBuffers(data, rowRanges);

Used as source in scatter and destination in gather operations

Page 13: Computer Science 320 Slicing and Dicing Data with Buffers

Example: Matrix Partition by Columns

int[] data = new int[4][8];

Range[] colRanges = new Range(0, 7).subranges(4);

IntegerBuf colBufs = IntegerBuf.colSliceBuffers(data, colRanges);

Used as source in scatter and destination in gather operations

Page 14: Computer Science 320 Slicing and Dicing Data with Buffers

Example: Matrix Partition by Patchesint[] data = new int[4][8];

Range[] rowRanges = new Range(0, 3).subranges(2);

Range[] colRanges = new Range(0, 7).subranges(2);

IntegerBuf patchBufs = IntegerBuf.patchBuffers(data, rowRanges, colRanges);

Used as source in scatter and destination in gather operations