function total = prime_fun ( n )

  spmd

    nlo = ( n * ( labindex - 1 ) ) / numlabs + 1;
    nhi = ( n *   labindex       ) / numlabs;
    if ( nlo == 1 )
      nlo = 2;
    end

    total_part = 0;

    for i = nlo : nhi

      prime = 1;
      for j = 2 : i - 1
        if ( mod ( i, j ) == 0 )
          prime = 0;
          break
        end
      end

      total_part = total_part + prime;
    end

    total_spmd = gplus ( total_part );
  end

  total = total_spmd{1};
  return
end
