<commit_before>-- Copyright 2017 Stanford University
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--     http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

import "regent"

local cexternal_test
do
  assert(os.getenv('LG_RT_DIR') ~= nil, "$LG_RT_DIR should be set!")
  local root_dir = arg[0]:match(".*/") or "./"
  local runtime_dir = os.getenv('LG_RT_DIR') .. "/"
  local legion_dir = runtime_dir .. "legion/"
  local mapper_dir = runtime_dir .. "mappers/"
  local realm_dir = runtime_dir .. "realm/"
  local external_test_cc = root_dir .. "external_test.cc"
  local external_test_so
  if os.getenv('SAVEOBJ') == '1' then
    external_test_so = root_dir .. "libexternal_test.so"
  else
    external_test_so = os.tmpname() .. ".so" -- root_dir .. "mapper.so"
  end
  local cxx = os.getenv('CXX') or 'c++'

  local cxx_flags = os.getenv('CC_FLAGS') or ''
  cxx_flags = cxx_flags .. " -O2 -Wall -Werror"
  if os.execute('test "$(uname)" = Darwin') == 0 then
    cxx_flags =
      (cxx_flags ..
         " -dynamiclib -single_module -undefined dynamic_lookup -fPIC")
  else
    cxx_flags = cxx_flags .. " -shared -fPIC"
  end

  local cmd = (cxx .. " " .. cxx_flags .. " -I " .. runtime_dir .. " " ..
                 " -I " .. mapper_dir .. " " .. " -I " .. legion_dir .. " " ..
                 " -I " .. realm_dir .. " " .. external_test_cc .. " -o " .. external_test_so)
  if os.execute(cmd) ~= 0 then
    print("Error: failed to compile " .. external_test_cc)
    assert(false)
  end
  terralib.linklibrary(external_test_so)
  cexternal_test =
    terralib.includec("external_test.h", {"-I", root_dir, "-I", runtime_dir,
                                          "-I", mapper_dir, "-I", legion_dir,
                                          "-I", realm_dir})
end

local c = regentlib.c

fspace fs
{
  _0 : float,
  _1 : float,
  _2 : float,
}

task init(r : region(ispace(int2d), fs))
where reads writes(r)
do
  var cnt = 0
  for e in r do
    e._0 = 3 * cnt
    e._1 = 3 * cnt + 1
    e._2 = 3 * cnt + 2
    cnt += 1
  end
end

terra get_raw_ptr(pr : c.legion_physical_region_t[1],
                  fld : c.legion_field_id_t[1])
  var fa = c.legion_physical_region_get_field_accessor_generic(pr[0], fld[0])
  var rect : c.legion_rect_2d_t
  var subrect : c.legion_rect_2d_t
  var offsets : c.legion_byte_offset_t[2]
  rect.lo.x[0] = 0
  rect.lo.x[1] = 0
  rect.hi.x[0] = 3
  rect.hi.x[1] = 3<commit_msg>regent: Fix off-by-one bug<commit_after>-- Copyright 2017 Stanford University
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--     http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

import "regent"

local cexternal_test
do
  assert(os.getenv('LG_RT_DIR') ~= nil, "$LG_RT_DIR should be set!")
  local root_dir = arg[0]:match(".*/") or "./"
  local runtime_dir = os.getenv('LG_RT_DIR') .. "/"
  local legion_dir = runtime_dir .. "legion/"
  local mapper_dir = runtime_dir .. "mappers/"
  local realm_dir = runtime_dir .. "realm/"
  local external_test_cc = root_dir .. "external_test.cc"
  local external_test_so
  if os.getenv('SAVEOBJ') == '1' then
    external_test_so = root_dir .. "libexternal_test.so"
  else
    external_test_so = os.tmpname() .. ".so" -- root_dir .. "mapper.so"
  end
  local cxx = os.getenv('CXX') or 'c++'

  local cxx_flags = os.getenv('CC_FLAGS') or ''
  cxx_flags = cxx_flags .. " -O2 -Wall -Werror"
  if os.execute('test "$(uname)" = Darwin') == 0 then
    cxx_flags =
      (cxx_flags ..
         " -dynamiclib -single_module -undefined dynamic_lookup -fPIC")
  else
    cxx_flags = cxx_flags .. " -shared -fPIC"
  end

  local cmd = (cxx .. " " .. cxx_flags .. " -I " .. runtime_dir .. " " ..
                 " -I " .. mapper_dir .. " " .. " -I " .. legion_dir .. " " ..
                 " -I " .. realm_dir .. " " .. external_test_cc .. " -o " .. external_test_so)
  if os.execute(cmd) ~= 0 then
    print("Error: failed to compile " .. external_test_cc)
    assert(false)
  end
  terralib.linklibrary(external_test_so)
  cexternal_test =
    terralib.includec("external_test.h", {"-I", root_dir, "-I", runtime_dir,
                                          "-I", mapper_dir, "-I", legion_dir,
                                          "-I", realm_dir})
end

local c = regentlib.c

fspace fs
{
  _0 : float,
  _1 : float,
  _2 : float,
}

task init(r : region(ispace(int2d), fs))
where reads writes(r)
do
  var cnt = 0
  for e in r do
    e._0 = 3 * cnt
    e._1 = 3 * cnt + 1
    e._2 = 3 * cnt + 2
    cnt += 1
  end
end

terra get_raw_ptr(pr : c.legion_physical_region_t[1],
                  fld : c.legion_field_id_t[1])
  var fa = c.legion_physical_region_get_field_accessor_generic(pr[0], fld[0])
  var rect : c.legion_rect_2d_t
  var subrect : c.legion_rect_2d_t
  var offsets : c.legion_byte_offset_t[2]
  rect.lo.x[0] = 0
  rect.lo.x[1] = 0
  rect.hi.x[0] = 2
  rect.hi.x[1] = 2
{'fraction_non_alphanumeric': 0.14061683220073184, 'fraction_numerical': 0.014636696288552013, 'mean_word_length': 2.4620024125452353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4420936', 'n_tokens_mistral': 2092, 'n_tokens_neox': 2049, 'n_words': 550}