multiply.txt Trachtenberg Multiplication using multi-tasking Each process does 1 pass char result[11]; int N = 6; // number of digits int a[] = { 1, 2, 3, 4, 5, 6}; int b[] = { 7, 8, 9, 0, 1, 2); process start end number position position ------- -------- -------- ps1 6 to 6 ps2 5 to 6 ps3 4 to 6 ps4 3 to 6 ps5 2 to 6 ps6 1 to 6 ps7 1 to 5 ps8 1 to 4 ps9 1 to 3 ps10 1 to 2 ps11 1 to 1 ps = 0 // 0 ls = rs = N-1; for (i=1; i < N*2-1;i++ { if (i < n*2-1) { send_to_ps(i,ls); send_to_ps(i,rs); } if (i==1) send_to_ps(ps1, 0) if (ls > 0) ls--; else rs--; } for (i=1; i < N*2-1;i++ { read(digit, psnumber) result[psnumber]= digit; } print result ps = 1..N*2-1 // 1 2 3 4 5 6 7 8 9 10 11 read(psnumber, ls) read(psnumber, rs) carry = 0; for (k=ls, j=rs; k <= rs; k++,j--) carry += a[j]*b[k]; read(psnumber, tcarry); carry += tcarry; rmd = carry%10; // pick off right-most digit send to ps(0,rmd); carry /= 10; send to ps(ps+1,carry); ps = N*2 // 12 read(psnumber,carry); rmd = carry%10; send to ps(0,rmd);