Skip to content

Commit 6ae19de

Browse files
Added score-based loop
1 parent 69a0e4c commit 6ae19de

10 files changed

Lines changed: 143 additions & 30 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ $(OBJ_DIR)/common.o: $(SRC_DIR)/common.cpp
3737
$(CXX) $(CXXFLAGS) -c $< -o $@
3838

3939
$(OBJ_DIR)/kmeans_cl.o: $(KMEANS_LIB_DIR)/kmeans_cl.c $(KMEANS_LIB_DIR)/kmeans_cl.h
40-
$(CC) $(CFLAGS) -c $< -o $@
40+
$(CXX) $(CXXFLAGS) -c $< -o $@
4141

4242
$(OBJ_DIR)/kmeans.o: $(KMEANS_LIB_DIR)/kmeans.c
43-
$(CC) $(CFLAGS) -c $< -o $@
43+
$(CXX) $(CXXFLAGS) -c $< -o $@
4444

4545
$(OBJ_DIR)/dbscan.o: $(DBSCAN_LIB_DIR)/dbscan.cpp $(DBSCAN_LIB_DIR)/dbscan.hpp
4646
$(CXX) $(CXXFLAGS) -c $< -o $@

common.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "common.h"
2+
#include <algorithm>
23
#include <cmath>
34
#include <cstddef> // For offsetof
45
#include <fstream>

vendor/kmeans/kmeans.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ int kmeans(int myrank, const char *str, const point *pts, int n, int *res) {
6868
config.centroid_method = pt_centroid;
6969

7070
/* Inputs for K-means */
71-
config.objs = calloc(config.num_objs, sizeof(Pointer));
72-
config.centers = calloc(config.k, sizeof(Pointer));
73-
config.clusters = calloc(config.num_objs, sizeof(int));
71+
config.objs = (Pointer*) calloc(config.num_objs, sizeof(Pointer));
72+
config.centers = (Pointer*) calloc(config.k, sizeof(Pointer));
73+
config.clusters = (int *) calloc(config.num_objs, sizeof(int));
7474

7575
/* Storage for raw data */
7676

77-
init = calloc(config.k, sizeof(point));
77+
init = (point *) calloc(config.k, sizeof(point));
7878

7979
for (i = 0; i < n; i++) {
8080
/* Pointer to raw data */
81-
config.objs[i] = &(pts[i]);
81+
config.objs[i] = (Pointer) &(pts[i]);
8282
}
8383

8484
/* Populate the initial means vector with random start points */

vendor/kmeans/kmeans_cl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ kmeans_cl(kmeans_config *config)
274274
* Previous cluster state array. At this time, r doesn't mean anything
275275
* but it's ok
276276
*/
277-
clusters_last = kmeans_malloc(clusters_sz);
277+
clusters_last = (int *) kmeans_malloc(clusters_sz);
278278

279279
while (1)
280280
{

workflow/cwl/clt/clustering.cwl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ inputs:
2323
inputBinding:
2424
position: 1
2525
prefix: -n
26+
seed:
27+
type: int
28+
inputBinding:
29+
position: 6
2630
outputs:
2731
indices:
2832
type: File

workflow/cwl/clt/silhouette.cwl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
cwlVersion: v1.2
2+
class: CommandLineTool
3+
requirements:
4+
ToolTimeLimit:
5+
timelimit: 300
6+
arguments:
7+
- position: 5
8+
valueFrom: output.txt
9+
inputs:
10+
annealing:
11+
type: File
12+
inputBinding:
13+
position: 4
14+
indices:
15+
type: File
16+
inputBinding:
17+
position: 3
18+
points:
19+
type: File
20+
inputBinding:
21+
position: 2
22+
silhouette:
23+
type: File
24+
inputBinding:
25+
position: 1
26+
outputs:
27+
output:
28+
type: float
29+
outputBinding:
30+
glob: output.txt
31+
loadContents: true
32+
outputEval: $(parseFloat(self[0].contents))

workflow/cwl/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ clustering_src:
88
path: ../../Makefile
99
- class: File
1010
path: ../../clustering.cpp
11+
- class: File
12+
path: ../../common.cpp
1113
- class: File
1214
path: ../../points.cpp
15+
- class: File
16+
path: ../../silhouette.cpp
1317
- class: Directory
1418
path: ../../include
1519
- class: Directory

workflow/cwl/main.cwl

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
cwlVersion: v1.2
22
class: Workflow
3+
4+
$namespaces:
5+
cwltool: "http://commonwl.org/cwltool#"
6+
37
requirements:
48
StepInputExpressionRequirement: {}
59
ToolTimeLimit:
@@ -14,13 +18,15 @@ inputs:
1418
type: array
1519
items: [File, Directory]
1620
points: File
17-
processes:
18-
type: int
19-
default: 3
21+
processes: int?
22+
threshold: float?
2023
outputs:
21-
annealing:
24+
output:
2225
type: File
23-
outputSource: annealing/output
26+
outputSource: loop/output
27+
score:
28+
type: float
29+
outputSource: loop/score
2430
steps:
2531
build-clustering:
2632
run: clt/build.cwl
@@ -29,23 +35,81 @@ steps:
2935
output_path:
3036
valueFrom: build/bin/clustering
3137
out: [output]
32-
clustering:
33-
run: clt/clustering.cwl
34-
in:
35-
clustering: build-clustering/output
36-
points: points
37-
processes: processes
38-
out: [indices, output]
3938
build-annealing:
4039
run: clt/build.cwl
4140
in:
4241
src: annealing_src
4342
output_path:
4443
valueFrom: build/bin/simAnnSingle.out
4544
out: [output]
46-
annealing:
47-
run: clt/annealing.cwl
45+
build-silhouette:
46+
run: clt/build.cwl
4847
in:
49-
annealing: build-annealing/output
50-
qubo: clustering/output
48+
src: clustering_src
49+
output_path:
50+
valueFrom: build/bin/silhouette
5151
out: [output]
52+
loop:
53+
requirements:
54+
InlineJavascriptRequirement: {}
55+
cwltool:Loop:
56+
loopWhen: $(inputs.score < inputs.threshold)
57+
loop:
58+
score: score
59+
seed:
60+
valueFrom: $(inputs.seed + 1)
61+
outputMethod: last
62+
run:
63+
class: Workflow
64+
inputs:
65+
annealing_script: File
66+
clustering_script: File
67+
points: File
68+
processes:
69+
type: int
70+
default: 3
71+
seed: int
72+
silhouette_script: File
73+
outputs:
74+
output:
75+
type: File
76+
outputSource: annealing/output
77+
score:
78+
type: float
79+
outputSource: silhouette/output
80+
steps:
81+
clustering:
82+
run: clt/clustering.cwl
83+
in:
84+
clustering: clustering_script
85+
points: points
86+
processes: processes
87+
seed: seed
88+
out: [indices, output]
89+
annealing:
90+
run: clt/annealing.cwl
91+
in:
92+
annealing: annealing_script
93+
qubo: clustering/output
94+
out: [output]
95+
silhouette:
96+
run: clt/silhouette.cwl
97+
in:
98+
silhouette: silhouette_script
99+
points: points
100+
indices: clustering/indices
101+
annealing: annealing/output
102+
out: [output]
103+
in:
104+
annealing_script: build-annealing/output
105+
clustering_script: build-clustering/output
106+
points: points
107+
processes: processes
108+
seed:
109+
default: 0
110+
score:
111+
default: 0.0
112+
silhouette_script: build-silhouette/output
113+
threshold:
114+
default: 0.5
115+
out: [output, score]

workflow/streamflow.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@ workflows:
66
file: cwl/main.cwl
77
settings: cwl/config.yml
88
bindings:
9+
- step: /build-annealing
10+
target:
11+
deployment: leonardo
12+
service: booster
913
- step: /build-clustering
1014
target:
1115
deployment: leonardo
1216
service: dcgp
13-
- step: /clustering
17+
- step: /build-silhouette
1418
target:
1519
deployment: leonardo
1620
service: dcgp
17-
- step: /build-annealing
21+
- step: /loop/clustering
1822
target:
1923
deployment: leonardo
20-
service: booster
21-
- step: /annealing
24+
service: dcgp
25+
- step: /loop/annealing
2226
target:
2327
deployment: leonardo
2428
service: booster
29+
- step: /loop/silhouette
30+
target:
31+
deployment: leonardo
32+
service: dcgp
2533
database:
2634
type: sqlite
2735
config:
@@ -39,7 +47,7 @@ deployments:
3947
leonardo:
4048
type: slurm
4149
config:
42-
maxConcurrentJobs: 2
50+
maxConcurrentJobs: 3
4351
services:
4452
booster:
4553
account: IscrC_SHPC-QC

0 commit comments

Comments
 (0)