Download pseudo source code

procedure main(argc, argv[])
  if argc = 3 then
    shared const overall_start = integer(argv[1])
    shared const overall_finish = integer(argv[2])

    shared const process_start = calculate_start(process_number \
      , overall_finish, process_count, overall_start)
    shared const process_finish = calculate_finish(process_number \
      , overall_finish, process_count, overall_start)
    shared const process_size = process_finish - process_start
    // E.g: hostname2:1: range [12, 20[ size 8
    print process_hostname, ':', process_number, ": range [", process_start
      , ", ", process_finish, "[ size ", process_size

    parallel do
      declare thread_start := -1
      declare thread_finish := -1

      parallel for index := process_start to process_finish using block mapping do
        if thread_start = -1 then
          thread_start := index
        end if
        thread_finish := index
      end for

      thread_finish := thread_finish + 1
      declare constant thread_size = thread_finish - thread_start
      // E.g: hostname2:1.1: range [15,18[ size 3
      print '\t', process_hostname, ':', process_number, '.', thread_number, \
        ": range [", thread_start, ", ",  thread_finish, "[ size ", thread_size
    end parallel
  end if
end procedure

function calculate_start(rank, end, workers, begin = 0)
  declare constant range = end - begin
  return begin + rank * div(range, workers) + min(rank, mod(range, workers))
end function

function calculate_finish(rank, end, workers, begin)
  return calculate_start(rank + 1, end, workers, begin)
end function