function [u,k] = BlockJacobi2(A,b,u0,prec,maxIters,I)

u = u0;
r = b-A*u;
initNorm = norm(r);
N = length(I);
n = zeros(N,1);
for i=1:N
    n(i) = length(I{i});
    invA{i} = inv(A(I{i},I{i}));
end

for k=1:maxIters        

    for i=1:N
        u(I{i}) = u(I{i}) + invA{i}*r(I{i});    
    end
    r = b-A*u;    

    if norm(r)/initNorm < prec
        break;
    end
end

