summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornasr <nsrddyn@gmail.com>2025-11-26 23:11:25 +0100
committernasr <nsrddyn@gmail.com>2025-11-26 23:11:25 +0100
commit5c90505fe7b6566049bead5e36a5e3f73d844413 (patch)
treed65a6402dd93d0e8ccb464eb5eab382e625a67d1 /src
parentd6f99d058b34d5b6fbc3f630bf491b302cdf324f (diff)
chore: file refactor, imported zio
next steps are running the threads multithreaded and measuring for errors
Diffstat (limited to 'src')
-rw-r--r--src/Enums/Status.scala (renamed from src/main/scala/com/nsrddyn/Enums/Status.scala)0
-rw-r--r--src/Main.scala (renamed from src/main/scala/com/nsrddyn/Main.scala)10
-rw-r--r--src/Ops/Prime.scala138
-rw-r--r--src/Tests/Tests.scala (renamed from src/main/scala/com/nsrddyn/Tests/CholeskyDecompositionTest.scala)11
-rw-r--r--src/Tools/Benchmark.scala (renamed from src/main/scala/com/nsrddyn/Tools/Benchmark.scala)0
-rw-r--r--src/Traits/Workload.scala (renamed from src/main/scala/com/nsrddyn/Traits/Workload.scala)2
-rw-r--r--src/main/scala/com/nsrddyn/ALU/Hash.scala31
-rw-r--r--src/main/scala/com/nsrddyn/ALU/Prime.scala64
-rw-r--r--src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala46
-rw-r--r--src/main/scala/com/nsrddyn/FPU/FPU.scala6
-rw-r--r--src/main/scala/com/nsrddyn/FPU/Matrix.scala5
11 files changed, 154 insertions, 159 deletions
diff --git a/src/main/scala/com/nsrddyn/Enums/Status.scala b/src/Enums/Status.scala
index e69de29..e69de29 100644
--- a/src/main/scala/com/nsrddyn/Enums/Status.scala
+++ b/src/Enums/Status.scala
diff --git a/src/main/scala/com/nsrddyn/Main.scala b/src/Main.scala
index 1619a2e..39851cb 100644
--- a/src/main/scala/com/nsrddyn/Main.scala
+++ b/src/Main.scala
@@ -11,18 +11,20 @@ enum Status:
case FAIL
-object Torque {
+object Torque extends ZIOAppDefault {
println("hello world")
- @main def main(args: String*): Unit = {
- // ANSI ESCAPE CODE: clear screen
- println("\u001b[2J\u001b[H")
+ @main def main(args: String*): Unit = { println("\u001b[2J\u001b[H")
println("--- TORQUE STRESS TESTING UTILITY ---")
var tester: CholeskyDecompositionTest = new CholeskyDecompositionTest
println(tester.test())
}
+
+ var p: Prime = new Prime
+ p.run()
+
}
diff --git a/src/Ops/Prime.scala b/src/Ops/Prime.scala
new file mode 100644
index 0000000..bd93ee1
--- /dev/null
+++ b/src/Ops/Prime.scala
@@ -0,0 +1,138 @@
+package com.nsrddyn.ops
+import com.nsrddyn.tools.Benchmark
+import scala.util.hashing
+import scala.util.hashing.MurmurHash3
+import com.nsrddyn.Traits.*
+import scala.math._
+import scala.collection.immutable.ListSet
+import scala.collection.mutable.ArrayBuffer
+
+
+class Prime() {
+
+ /*
+ * Calculate all primes up to limit
+ * This should stress the ALU in someway,
+ * doing this in a predictable manner,
+ * will hopefully keep the cpu pipeline busy
+ * and that way stress the branch predictor
+ *
+ * math.sqrt(n) => a prime number has 2 factors, one of the factors
+ * of the prime numbers has to be smaller then n
+ * after that we check if the number is whole number and thereby checking if its a prime
+ *
+ */
+
+
+ /*
+ * TODO: I did the countrary of what i wanted to accieve with the is prime function
+ * We want the function to be less optimized so that the CPU has more work == more stress
+ */
+
+
+ def isPrime(n: Int): Boolean = {
+ if n <= 1 then false
+ else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0)
+
+
+ }
+
+ def run(n: Int, result: Boolean): Unit = {
+
+ for i <- 0 to n do if isPrime(i) == result then println("true") else println("false")
+ }
+
+
+}
+
+
+
+
+class PrimeRunner {
+
+
+ def run(threads: Int): Unit = {
+
+ val pr = new Prime()
+ val br = new Benchmark()
+
+ /*
+ * test cases
+ *
+ * 7919 true
+ * 2147483647 false
+ */
+
+ val time = pr.run(7919, true)
+ println(time)
+
+ }
+}
+
+
+class Hash {
+
+ def run(word: String, loopSize: Int): Unit = {
+
+ /* TODO: implement ALU friendly, so high speed hashing
+ * to continuously loop over voor stressing
+ * ALU
+ *
+ * While looking for hashing algorithmes to implement I stumbled on:
+ * https://scala-lang.org/api/3.x/scala/util/hashing/MurmurHash3$.html
+ *
+ * which is an implemntation of **smasher** http://github.com/aappleby/smhasher
+ * the exact type of hashing algorithm I was looking for
+ *
+ * In the scala description they state: "This algorithm is designed to generate
+ * well-distributed non-cryptographic hashes. It is designed to hash data in 32 bit chunks (ints). "
+ *
+ * (ints) -> ALU
+ *
+ */
+
+ for i <- 0 to loopSize do MurmurHash3.stringHash(word)
+
+ }
+}
+
+class CholeskyDecomposition {
+
+ /*
+ * Floating point operation to stress the cpu
+ * Calculate the number of KFLOPS / FLOPS
+ * implementation of the Cholesky decomposition
+ * More information on the Cholesky decomposition at:
+ * https://en.wikipedia.org/wiki/Cholesky_decomposition
+ *
+ * Linpack uses the cholesky decomposition
+ * https://www.netlib.org/linpack/
+ *
+ * https://www.geeksforgeeks.org/dsa/cholesky-decomposition-matrix-decomposition/
+ *
+ * The Cholesky decomposition maps matrix A into the product of A = L · LH where L is the lower triangular matrix and LH is the transposed,
+ * complex conjugate or Hermitian, and therefore of upper triangular form (Fig. 13.6).
+ * This is true because of the special case of A being a square, conjugate symmetric matrix.
+ */
+
+ def run(matrix: Vector[Vector[Int]]): Unit = {
+
+ val size: Int = matrix.size
+ val lower: ArrayBuffer[ArrayBuffer[Int]] = ArrayBuffer[ArrayBuffer[Int]]()
+
+ for
+ i <- 0 to size
+ j <- 0 until i
+ do
+ if i == j then lower(i)(j) = getSquaredSummation(lower, i, j, matrix) else lower(j)(j) = getReversedSummation(lower, i, j, matrix)
+
+ }
+
+ private def getReversedSummation(lower: ArrayBuffer[ArrayBuffer[Int]], i: Int, j: Int, matrix: Vector[Vector[Int]]) = {
+ math.sqrt(matrix(j)(j) - (0 until j).map { k => lower(i)(k) * lower(j)(k) }.sum).toInt
+ }
+ private def getSquaredSummation(lower: ArrayBuffer[ArrayBuffer[Int]], i: Int, j: Int, matrix: Vector[Vector[Int]]) = {
+ ((matrix(i)(j) - (0 until j).map { k => math.pow(lower(j)(k), 2)}.sum) / lower(j)(j)).toInt
+ }
+}
+
diff --git a/src/main/scala/com/nsrddyn/Tests/CholeskyDecompositionTest.scala b/src/Tests/Tests.scala
index 8361547..88fd139 100644
--- a/src/main/scala/com/nsrddyn/Tests/CholeskyDecompositionTest.scala
+++ b/src/Tests/Tests.scala
@@ -2,8 +2,17 @@ package com.nsrddyn.Tests
import com.nsrddyn.fpu.CholeskyDecomposition
import scala.collection.immutable.ListSet
+import zio._
-class CholeskyDecompositionTest extends CholeskyDecomposition {
+class TestsRunner extends ZIOAppDefault {
+
+ def run =
+ println("Hello world")
+
+
+}
+
+class CholeskyDecompositionTest {
def test(): Unit = {
diff --git a/src/main/scala/com/nsrddyn/Tools/Benchmark.scala b/src/Tools/Benchmark.scala
index a0b388b..a0b388b 100644
--- a/src/main/scala/com/nsrddyn/Tools/Benchmark.scala
+++ b/src/Tools/Benchmark.scala
diff --git a/src/main/scala/com/nsrddyn/Traits/Workload.scala b/src/Traits/Workload.scala
index 2339ede..b547a6f 100644
--- a/src/main/scala/com/nsrddyn/Traits/Workload.scala
+++ b/src/Traits/Workload.scala
@@ -1,7 +1,5 @@
package com.nsrddyn.Traits
-import zio._
-
trait Workload {
def name: String
diff --git a/src/main/scala/com/nsrddyn/ALU/Hash.scala b/src/main/scala/com/nsrddyn/ALU/Hash.scala
deleted file mode 100644
index 9dc5a98..0000000
--- a/src/main/scala/com/nsrddyn/ALU/Hash.scala
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.nsrddyn.alu
-
-import scala.util.hashing
-
-class Hash {
-
-import scala.util.hashing.MurmurHash3
-
- def run(word: String, loopSize: Int): Unit = {
-
- /* TODO: implement ALU friendly, so high speed hashing
- * to continuously loop over voor stressing
- * ALU
- *
- * While looking for hashing algorithmes to implement I stumbled on:
- * https://scala-lang.org/api/3.x/scala/util/hashing/MurmurHash3$.html
- *
- * which is an implemntation of **smasher** http://github.com/aappleby/smhasher
- * the exact type of hashing algorithm I was looking for
- *
- * In the scala description they state: "This algorithm is designed to generate
- * well-distributed non-cryptographic hashes. It is designed to hash data in 32 bit chunks (ints). "
- *
- * (ints) -> ALU
- *
- */
-
- for i <- 0 to loopSize do MurmurHash3.stringHash(word)
-
- }
-}
diff --git a/src/main/scala/com/nsrddyn/ALU/Prime.scala b/src/main/scala/com/nsrddyn/ALU/Prime.scala
deleted file mode 100644
index a6c7d15..0000000
--- a/src/main/scala/com/nsrddyn/ALU/Prime.scala
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.nsrddyn.alu
-import com.nsrddyn.alu.Prime
-import com.nsrddyn.tools.Benchmark
-import com.nsrddyn.test
-
-class Prime() extends {
-
- /*
- * Calculate all primes up to limit
- * This should stress the ALU in someway,
- * doing this in a predictable manner,
- * will hopefully keep the cpu pipeline busy
- * and that way stress the branch predictor
- *
- * math.sqrt(n) => a prime number has 2 factors, one of the factors
- * of the prime numbers has to be smaller then n
- * after that we check if the number is whole number and thereby checking if its a prime
- *
- */
-
-
- /*
- * TODO: I did the countrary of what i wanted to accieve with the is prime function
- * We want the function to be less optimized so that the CPU has more work == more stress
- */
-
-
- def isPrime(n: Int): Boolean = {
- if n <= 1 then false
- else !(2 to math.sqrt(n).toInt).exists(i => n % i == 0)
-
-
- }
-
- def run(n: Int, result: Boolean): Unit = {
-
- for i <- 0 to n do if isPrime(i) == result then println("true") else println("false")
- }
-
-
-}
-
-
-
-
-class PrimeRunner extends Workload {
-
- def run(threads: Int): Unit = {
-
- val pr = new Prime()
- val br = new Benchmark()
-
- /*
- * test cases
- *
- * 7919 true
- * 2147483647 false
- */
-
- val time = pr.run(7919, true)
- println(time)
-
- }
-}
diff --git a/src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala b/src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala
deleted file mode 100644
index 895473a..0000000
--- a/src/main/scala/com/nsrddyn/FPU/CholeskyDecomposition.scala
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.nsrddyn.fpu
-
-import scala.math._
-import scala.collection.immutable.ListSet
-import scala.collection.mutable.ArrayBuffer
-
-class CholeskyDecomposition {
-
- /*
- * Floating point operation to stress the cpu
- * Calculate the number of KFLOPS / FLOPS
- * implementation of the Cholesky decomposition
- * More information on the Cholesky decomposition at:
- * https://en.wikipedia.org/wiki/Cholesky_decomposition
- *
- * Linpack uses the cholesky decomposition
- * https://www.netlib.org/linpack/
- *
- * https://www.geeksforgeeks.org/dsa/cholesky-decomposition-matrix-decomposition/
- *
- * The Cholesky decomposition maps matrix A into the product of A = L · LH where L is the lower triangular matrix and LH is the transposed,
- * complex conjugate or Hermitian, and therefore of upper triangular form (Fig. 13.6).
- * This is true because of the special case of A being a square, conjugate symmetric matrix.
- */
-
- def run(matrix: Vector[Vector[Int]]): Unit = {
-
- val size: Int = matrix.size
- val lower: ArrayBuffer[ArrayBuffer[Int]] = ArrayBuffer[ArrayBuffer[Int]]()
-
- for
- i <- 0 to size
- j <- 0 until i
- do
- if i == j then lower(i)(j) = getSquaredSummation(lower, i, j, matrix) else lower(j)(j) = getReversedSummation(lower, i, j, matrix)
-
- }
-
- private def getReversedSummation(lower: ArrayBuffer[ArrayBuffer[Int]], i: Int, j: Int, matrix: Vector[Vector[Int]]) = {
- math.sqrt(matrix(j)(j) - (0 until j).map { k => lower(i)(k) * lower(j)(k) }.sum).toInt
- }
- private def getSquaredSummation(lower: ArrayBuffer[ArrayBuffer[Int]], i: Int, j: Int, matrix: Vector[Vector[Int]]) = {
- ((matrix(i)(j) - (0 until j).map { k => math.pow(lower(j)(k), 2)}.sum) / lower(j)(j)).toInt
- }
-}
-
diff --git a/src/main/scala/com/nsrddyn/FPU/FPU.scala b/src/main/scala/com/nsrddyn/FPU/FPU.scala
deleted file mode 100644
index 6532476..0000000
--- a/src/main/scala/com/nsrddyn/FPU/FPU.scala
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.nsrddyn.fpu
-
-
-class FPU {
-
-}
diff --git a/src/main/scala/com/nsrddyn/FPU/Matrix.scala b/src/main/scala/com/nsrddyn/FPU/Matrix.scala
deleted file mode 100644
index 7f1bccf..0000000
--- a/src/main/scala/com/nsrddyn/FPU/Matrix.scala
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.nsrddyn.fpu
-
-class Matrix {
-
-}