Skip to content

Commit ce7ff5f

Browse files
authored
Merge pull request #194 from JohnLCaron/all_btree
Use readChunksConcurrent for all btree1 reading.
2 parents 47f3272 + c6045d1 commit ce7ff5f

36 files changed

Lines changed: 553 additions & 238 deletions

File tree

‎Readme.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# netchdf
2-
_last updated: 7/22/2025_
2+
_last updated: 7/25/2025_
33

44
This is a rewrite in Kotlin of parts of the devcdm and netcdf-java libraries.
55

@@ -133,7 +133,7 @@ For HDF5 files using deflate filters, the deflate library dominates the read tim
133133
are about 2X slower than native code. Unless the deflate libraries get better, there's not much gain in trying to make
134134
other parts of the code faster.
135135

136-
We will investigate using Kotlin coroutines to speed up performance bottlenecks.
136+
We are seeing 10x speedup on data reading. see https://github.com/JohnLCaron/netchdf/issues/189.
137137

138138

139139
### Goals and scope

‎core/src/commonMain/kotlin/com/sunya/cdm/api/Netchdf.kt‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ interface Netchdf : AutoCloseable {
2020
// iterate over all the chunks in section, order is arbitrary. TODO where is intersection with wantSection done ??
2121
fun <T> chunkIterator(v2: Variable<T>, wantSection: SectionPartial? = null, maxElements : Int? = null) : Iterator<ArraySection<T>>
2222

23+
// iterate over all the chunks in section, order is arbitrary, callbacks are in multiple threads.
2324
fun <T> readChunksConcurrent(v2: Variable<T>,
24-
lamda : (ArraySection<*>) -> Unit,
25+
lamda : (ArraySection<T>) -> Unit,
2526
done : () -> Unit,
2627
wantSection: SectionPartial? = null,
2728
nthreads: Int? = null) {
@@ -30,9 +31,9 @@ interface Netchdf : AutoCloseable {
3031
}
3132

3233
// the section describes the array chunk reletive to the variable's shape.
33-
data class ArraySection<T>(val array : ArrayTyped<T>, val section : Section) {
34+
data class ArraySection<T>(val array : ArrayTyped<T>, val chunkSection : Section) {
3435
fun intersect(wantSection: SectionPartial) : ArrayTyped<T> {
35-
// TODO
36+
// TODO ??
3637
return array
3738
}
3839
}

‎core/src/commonMain/kotlin/com/sunya/cdm/array/ArrayByte.kt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ class ArrayByte(shape : IntArray, val values: ByteArray) : ArrayTyped<Byte>(Data
3737
return dst
3838
}
3939

40+
override fun transfer(dst: Any, tc: TransferChunk) {
41+
val src = this.values
42+
val dest = dst as ByteArray
43+
repeat(tc.nelems) { dest[tc.destElem.toInt()+it] = src[tc.srcElem.toInt() + it] }
44+
}
45+
4046
}

‎core/src/commonMain/kotlin/com/sunya/cdm/array/ArrayDouble.kt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ class ArrayDouble(shape : IntArray, val values: DoubleArray) : ArrayTyped<Double
3636
}
3737
return dst
3838
}
39+
40+
override fun transfer(dst: Any, tc: TransferChunk) {
41+
val src = this.values
42+
val dest = dst as DoubleArray
43+
repeat(tc.nelems) { dest[tc.destElem.toInt()+it] = src[tc.srcElem.toInt() + it] }
44+
}
3945
}

‎core/src/commonMain/kotlin/com/sunya/cdm/array/ArrayFloat.kt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ class ArrayFloat(shape : IntArray, val values: FloatArray) : ArrayTyped<Float>(D
3737
return dst
3838
}
3939

40+
override fun transfer(dst: Any, tc: TransferChunk) {
41+
val src = this.values
42+
val dest = dst as FloatArray
43+
repeat(tc.nelems) { dest[tc.destElem.toInt()+it] = src[tc.srcElem.toInt() + it] }
44+
}
45+
4046
}

‎core/src/commonMain/kotlin/com/sunya/cdm/array/ArrayInt.kt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ class ArrayInt(shape : IntArray, val values: IntArray) : ArrayTyped<Int>(Datatyp
3636
}
3737
return dst
3838
}
39+
40+
override fun transfer(dst: Any, tc: TransferChunk) {
41+
val src = this.values
42+
val dest = dst as IntArray
43+
repeat(tc.nelems) { dest[tc.destElem.toInt()+it] = src[tc.srcElem.toInt() + it] }
44+
}
3945
}

‎core/src/commonMain/kotlin/com/sunya/cdm/array/ArrayLong.kt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ class ArrayLong(shape : IntArray, val values: LongArray) : ArrayTyped<Long>(Data
3636
}
3737
return dst
3838
}
39+
40+
override fun transfer(dst: Any, tc: TransferChunk) {
41+
val src = this.values
42+
val dest = dst as LongArray
43+
repeat(tc.nelems) { dest[tc.destElem.toInt()+it] = src[tc.srcElem.toInt() + it] }
44+
}
3945
}

‎core/src/commonMain/kotlin/com/sunya/cdm/array/ArrayOpaque.kt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,10 @@ class ArrayOpaque(shape : IntArray, val values : List<ByteArray>, val size : Int
7575
}
7676
}
7777

78+
override fun transfer(dst: Any, tc: TransferChunk) {
79+
val src = this.values
80+
val dest = dst as MutableList<ByteArray>
81+
repeat(tc.nelems) { dest[tc.destElem.toInt()+it] = src[tc.srcElem.toInt() + it] }
82+
}
7883

7984
}

‎core/src/commonMain/kotlin/com/sunya/cdm/array/ArrayShort.kt‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ class ArrayShort(shape : IntArray, val values: ShortArray) : ArrayTyped<Short>(D
3636
}
3737
return dst
3838
}
39+
40+
override fun transfer(dst: Any, tc: TransferChunk) {
41+
val src = this.values
42+
val dest = dst as ShortArray
43+
repeat(tc.nelems) { dest[tc.destElem.toInt()+it] = src[tc.srcElem.toInt() + it] }
44+
}
3945
}

‎core/src/commonMain/kotlin/com/sunya/cdm/array/ArrayString.kt‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.fleeksoft.charset.decodeToString
88
import com.sunya.cdm.api.*
99
import com.sunya.cdm.layout.IndexND
1010
import com.sunya.cdm.layout.IndexSpace
11+
import com.sunya.cdm.layout.TransferChunk
1112

1213
// fake ByteBuffer
1314
class ArrayString(shape : IntArray, val values : List<String>) : ArrayTyped<String>(Datatype.STRING, shape) {
@@ -37,6 +38,12 @@ class ArrayString(shape : IntArray, val values : List<String>) : ArrayTyped<Stri
3738
}
3839
return ArrayString(section.shape.toIntArray(), sectionList)
3940
}
41+
42+
override fun transfer(dst: Any, tc: TransferChunk) {
43+
val src = this.values
44+
val dest = dst as MutableList<String>
45+
repeat(tc.nelems) { dest[tc.destElem.toInt()+it] = src[tc.srcElem.toInt() + it] }
46+
}
4047
}
4148

4249
/**

0 commit comments

Comments
 (0)