Skip to content

Commit 4b3825f

Browse files
committed
modified Test file so it can be testet with different matric siszes
1 parent abf16ff commit 4b3825f

File tree

1 file changed

+71
-68
lines changed

1 file changed

+71
-68
lines changed

src/test/java/org/apache/sysds/test/functions/builtin/part2/BuiltinScaleRobustTest.java

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -46,79 +46,82 @@ private void runTest(boolean sparse, ExecType et) {
4646
rCmd = "Rscript " + fullRScriptName + " " + inputDir() + " " + expectedDir();
4747
String pyCmd = "python " + fullPyScriptName + " " + inputDir() + " " + expectedDir();
4848

49-
int[] numRowsArr = new int[]{10000};
50-
int numReps = 10;
51-
52-
for (int nRows : numRowsArr) {
53-
System.out.println("\n--- Running benchmark for matrix: " + nRows + " x " + cols + " ---");
54-
long totalTime = 0;
55-
56-
for (int i = 0; i < numReps; i++) {
57-
System.out.println("Iteration " + (i + 1) + " of " + numReps);
58-
59-
double[][] A = getRandomMatrix(nRows, cols, -10, 10, sparsity, 7);
60-
writeInputMatrixWithMTD("A", A, true);
61-
62-
// Measure memory BEFORE DML execution
63-
Runtime runtime = Runtime.getRuntime();
64-
runtime.gc();
65-
long memBefore = runtime.totalMemory() - runtime.freeMemory();
66-
67-
Statistics.reset();
68-
long startTime = System.nanoTime();
69-
runTest(true, false, null, -1); // DML run
70-
long endTime = System.nanoTime();
71-
long duration = endTime - startTime;
72-
totalTime += duration;
73-
74-
long memAfter = runtime.totalMemory() - runtime.freeMemory();
75-
long memUsedBytes = memAfter - memBefore;
76-
double memUsedMB = memUsedBytes / (1024.0 * 1024.0);
77-
// Includes everything
78-
System.out.println("Iteration time (ms): " + (duration / 1e6));
79-
System.out.println("Memory used (MB): " + memUsedMB);
80-
81-
// Run R and Python only for the first two iterations
82-
if (i == 0 || i == 1) {
83-
// Run R
84-
System.out.println("Running R script...");
85-
runRScript(true);
86-
87-
// Run Python
88-
System.out.println("Running Python script...");
89-
Process p = Runtime.getRuntime().exec(pyCmd);
90-
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
91-
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
92-
93-
String s;
94-
while ((s = stdInput.readLine()) != null) {
95-
System.out.println("[PYTHON OUT] " + s);
96-
}
97-
while ((s = stdError.readLine()) != null) {
98-
System.err.println("[PYTHON ERR] " + s);
99-
}
49+
int[] rowSizes = {10000, 20000, 50000/*, 100000 nur falls genug RAM*/};
50+
int[] colSizes = {100, 500, 1000};
51+
int numReps = 5;
52+
53+
for(int nRows : rowSizes) {
54+
for(int nCols : colSizes) {
55+
System.out.println("\n--- Benchmark for " + nRows + "×" + nCols + " ---");
56+
long totalTime = 0;
57+
58+
for(int rep=1; rep<=numReps; rep++) {
59+
System.out.println("Iteration " + rep + " of " + numReps);
60+
61+
// 1) Create input matrix
62+
double[][] A = getRandomMatrix(nRows, nCols, -10,10, sparsity, 7);
63+
writeInputMatrixWithMTD("A", A, true);
64+
65+
Runtime.getRuntime().gc();
66+
long memBefore = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
67+
68+
// 2) Run DML script
69+
Statistics.reset();
70+
long t0 = System.nanoTime();
71+
runTest(true, false, null, -1);
72+
long t1 = System.nanoTime();
73+
long duration = t1 - t0;
74+
totalTime += duration;
75+
76+
long memAfter = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
77+
System.out.println(" Time (ms): " + (duration/1e6));
78+
System.out.println(" Mem used (MB): " + ((memAfter - memBefore)/(1024*1024.0)));
79+
80+
// 3) Validate results
81+
if(rep == 1) {
82+
// Run R script
83+
System.out.println("Running R script...");
84+
runRScript(true);
85+
// Run Python
86+
System.out.println("Running Python script...");
87+
Process p = Runtime.getRuntime().exec(pyCmd);
88+
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
89+
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
90+
91+
String s;
92+
while ((s = stdInput.readLine()) != null) {
93+
System.out.println("[PYTHON OUT] " + s);
94+
}
95+
while ((s = stdError.readLine()) != null) {
96+
System.err.println("[PYTHON ERR] " + s);
97+
}
98+
99+
int exitCode = p.waitFor();
100+
if (exitCode != 0) {
101+
throw new RuntimeException("Python script failed with exit code: " + exitCode);
102+
}
103+
104+
// Compare results
105+
HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromOutputDir("B");
106+
HashMap<CellIndex, Double> rfile = readRMatrixFromExpectedDir("B");
107+
HashMap<CellIndex, Double> pyfile = readRMatrixFromExpectedDir("B");
108+
109+
System.out.println("Comparing DML vs R...");
110+
TestUtils.compareMatrices(dmlfile, rfile, eps, "DML", "R");
111+
112+
System.out.println("Comparing DML vs Python...");
113+
TestUtils.compareMatrices(dmlfile, pyfile, eps, "DML", "Python");
100114

101-
int exitCode = p.waitFor();
102-
if (exitCode != 0) {
103-
throw new RuntimeException("Python script failed with exit code: " + exitCode);
104115
}
105-
106-
// Compare results
107-
HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromOutputDir("B");
108-
HashMap<CellIndex, Double> rfile = readRMatrixFromExpectedDir("B");
109-
HashMap<CellIndex, Double> pyfile = readRMatrixFromExpectedDir("B");
110-
111-
System.out.println("Comparing DML vs R...");
112-
TestUtils.compareMatrices(dmlfile, rfile, eps, "DML", "R");
113-
114-
System.out.println("Comparing DML vs Python...");
115-
TestUtils.compareMatrices(dmlfile, pyfile, eps, "DML", "Python");
116116
}
117-
}
118117

119-
double avgTimeMs = totalTime / 1e6 / numReps;
120-
System.out.println(">>> Average time for " + nRows + "x" + cols + " over " + numReps + " runs: " + avgTimeMs + " ms");
118+
double avgMs = totalTime/1e6/numReps;
119+
System.out.println(">>> Average for " + nRows + "×" + nCols + ": " + avgMs + " ms");
120+
}
121121
}
122+
123+
124+
122125
} catch (Exception e) {
123126
throw new RuntimeException(e);
124127
} finally {

0 commit comments

Comments
 (0)