computer science 320 slicing and dicing data with buffers
TRANSCRIPT
![Page 1: Computer Science 320 Slicing and Dicing Data with Buffers](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/1.jpg)
Computer Science 320
Slicing and Dicing Data with Buffers
![Page 2: Computer Science 320 Slicing and Dicing Data with Buffers](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/2.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/3.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/4.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/5.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/6.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/7.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/8.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/9.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/10.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/11.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/12.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/13.jpg)
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](https://reader036.vdocuments.site/reader036/viewer/2022082610/56649da35503460f94a90628/html5/thumbnails/14.jpg)
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