https://kotlinlang.org logo
Title
f

Filipe Duarte

12/04/2021, 1:02 PM
I want to do parallel computations over collections and do parallel for loops. Java Streams with parallel for the first case? And the second case?
g

gildor

12/04/2021, 1:07 PM
Depends what kind operation you want to do in parallel, CPU heavy are work perfectly on Java parallel streams and you can use it from Kotlin too If your operations are async, coroutines is the way to go (of course you can use it for CPU heavy too, just do not expect better results than with ForkJoin from parallel streams)
f

Filipe Duarte

12/04/2021, 1:10 PM
CPU intensive tasks
g

gildor

12/04/2021, 1:13 PM
If you target only JVM and you fine with blocking nature of this API, I would just use parallel streams
f

Filipe Duarte

12/04/2021, 1:22 PM
When you say: “target only JVM,” are you excluding libraries with native dependencies for numerical computations? It will have many loops with numerical operations using nd4j (intensive linear algebra) and simple stuff. I think I could do parallel processes over a Java Stream with the nd4j for the numerical comp inside.
g

gildor

12/06/2021, 4:14 AM
are you excluding libraries with native dependencies for numerical computations?
No I mean that you do not write library for Kotlin MPP (JS/native)