-
Notifications
You must be signed in to change notification settings - Fork 2
/
SCAMP.q
50 lines (43 loc) · 1.71 KB
/
SCAMP.q
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
\l utl.q
a:"f"$(4,2048)#1000?1f;
w:30; t:til w; ca:til neg[w]+1+count a 0; .Q.gc[];
nak:a@\:ca+\:t;
/ shape - nt, nt, (count a) div 4, w
nnak:(`1`2`3`4)!(4,(count nak 0) div 4)#/:nak
/ distributed sdp - 4 workers
c1:hopen`::5042; c2:hopen `::5043; c3:hopen `::5044; c4:hopen `::5045;
sa:`1`2`3`4!(`::5043;`::5042;`::5044;`::5045)
/ nsdp:{[sa;x]sa[x]({x$\:/:''x};value nnak)}[sa;]each key nnak
/ Not tested
/ final code - distributed SDP
q)(value sa)[0] ({[vn;l]{[vn;x]vn[x]$\:/:/:vn}[vn;]each l};vn;til count vn)
c:0
q)shp {(value sa)[c] ({[vn;l]{[vn;x]vn[x]$\:/:/:vn}[vn;]each l};vn;til count vn)}each til count sa
///////// Not tested till here from line 13
/ gather chunks and re-assemble
/ ideally, these should be stored at each worker, then taken
/ for re-assembly - will implement that too
nsdp:{(,'/){(,/)x[y;]}[x;]each til count x}each nsdp
q)shp {(,'/)(,'/)x}each nsdp
///// q)k:{[vn](value sa)[c]({[vn;x]vn[x]$\:/:/:vn};vn;til count vn);c::c+1}each v
/ single process nsdp
/ \ts f:{{(nnak[x])[y]$\:/:/:nnak[x]}[x;]each til count nnak[x]}each key nnak
/ this might not work - need to test
/ \ts nsdp:{nak[x]$\:/:nak[x]}each til count nak
nsmasva:(var;avg)@\:/:/:nak
c0:sqrt nsmasva[;;0];c1:nsmasva[;;1];
v0:{(c0 x)*/:c0 x}each til count c0
v1:{(c1 x)*/:c1 x}each til count c1
Shorter code - but slower
/ \ts D:sqrt 2*w*(1-(nsdp-w*v1))%w*v0
/ this is 100% faster
\ts D:{sqrt 2*w*(1-nsdp[x]-w*v1[x])%w*v0[x]}each til count nsdp
/ replace 0n values with very large values
\ts D:(@/)''[D;where each '0n='D;:;"f"$2 xexp 32]
/ column-wise sort
\ts SD:flip each (asc)@\:''flip each D
.Q.gc[];
\ts {flip asc each flip D x}each til count D
kk:first each 'where each '(min each 'SD)=''SD
g:kk+\:\:t
\ts (a@\:ca+\:t),''{a[x]@g x}each til count a