1 function Xon = gram_schmidt_parallel(X, K, epsilon, n_on)
2 %
function Xon = gram_schmidt_parallel(X, k, epsilon, n_on)
3 % performs classical gram schmidt orthonormalization algorithm with
4 % re-orthogonalization. loss of orthogonality is a multiple of machine
6 % - X: vectors to be orthonormalized
7 % - K: inner product matrix
8 % - epsilon: norm threshold
9 % - n_on:
if given, first n_on vectors are assumed to be already orthonormal
17 nworkers = pool.NumWorkers;
19 ndofs = ceil(size(X, 1) / nworkers);
21 X_p = Composite(nworkers);
22 K_p = Composite(nworkers);
25 X_p{i} = X(1+(i-1)*ndofs : min(i*ndofs, size(X, 1)), :);
26 K_p{i} = K(1+(i-1)*ndofs : min(i*ndofs, size(K, 1)), :);
34 % storing matrix avoids multiple computation of inner products
35 KX_p = K_p * gcat(X_p, 1);
37 for i = (n_on + 1):nvecs
41 norm = sqrt(gplus(v_p
' * KX_p(:, i)));
45 % two orthogonalization iterations suffice
46 while norm > epsilon && niter < 2
48 KXv = gplus(KX_p' * v_p);
49 KXv(n_on+1 : end) = 0;
51 v_p = v_p - X_p * KXv;
53 w = K_p * gcat(v_p, 1);
55 norm = sqrt(gplus(v_p
' * w));
65 X_p(:, n_on) = v_p / norm;
66 KX_p(:, n_on) = w / norm;
71 Xon = vertcat(X_p{:});
72 Xon = Xon(:, 1:n_on{1});