computer science 320 slicing and dicing data with buffers
TRANSCRIPT
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
Example: A Single Item Integer Buffer
IntegerItemBuf buf = IntegerBuf.buffer();
buf.item = 42;
System.out.println(buf.item);
Example: An Integer Array Buffer
int[] data = new int[8];
IntegerBuf buf = IntegerBuf.buffer(data);
Example: An Array Slice
int[] data = new int[8];
Range sliceRange = new Range(2, 4);
IntegerBuf buf = IntegerBuf.buffer(data, sliceRange);
Example: Range Stride > 1
int[] data = new int[8];
Range evenRange = new Range(0, 6, 2);
IntegerBuf buf = IntegerBuf.buffer(data, evenRange);
Example: Partitioning an Array
int[] data = new int[8];
Range[] sliceRanges = new Range(0, 7).subranges(4);
IntegerBuf[] sliceBufs = IntegerBuf.sliceBuffers(data, sliceRanges);
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
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
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
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
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
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
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