Hi, all: (Is StackOverflow now the preferred channel for questions, or is here still good?)
I’m trying to write a program with a ragged associative array to describe a
graph’s edges - where the key is a string (say) and the value is an array of
non-fixed size - and I quickly get runtime errors once the associative array
gets long enough. A simple example follows below (and in attachment):
module ragged_associative_array {
record array_of_ints {
var arr : [1..0] int;
}
config const maxsize = 12;
proc main() {
var strs: domain(string);
var dict_of_array_of_ints : [strs] array_of_ints;
for i in 1..maxsize do
dict_of_array_of_ints[i:string].arr.push_back(i);
for str in strs do
writeln(str, ": ", dict_of_array_of_ints[str]);
}
}
Running gives:
$ chpl -o ragged_associative_array ragged_associative_array.chpl
$ ./ragged_associative_array --maxsize=11
10: (arr = 10)
11: (arr = 11)
9: (arr = 9)
8: (arr = 8)
5: (arr = 5)
4: (arr = 4)
7: (arr = 7)
6: (arr = 6)
1: (arr = 1)
3: (arr = 3)
2: (arr = 2)
$ ./ragged_associative_array --maxsize=12
ragged_associative_array.chpl:13: error: halt reached - assigning between
arrays of different shapes in dimension 1: 0 vs. 1
I don’t hit this problem for a non-associative array (e.g., var
dict_of_array_of_ints : [1..maxsize] array_of_ints), at least not at the same
problem size. (Having a record array_of_ints seems to be necessary; I can’t
use a type alias or just have e.g. var dict_of_array_of_ints : [1..maxsize]
[1..0] int or else I I immediately the runtime error “cannot call push_back on
an array defined over a domain with multiple arrays” ,which I guess I can
understand). Having a fixed maximum size and count field works, but is
something I’m trying to avoid.
This is on my mac with the current homebrew install:
machine info: Darwin coredump.local 16.6.0 Darwin Kernel Version 16.6.0: Fri
Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
CHPL_HOME: *
script location: /usr/local/Cellar/chapel/1.15.0/libexec/util
CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: clang
CHPL_TARGET_ARCH: native
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_MAKE: make
CHPL_ATOMICS: intrinsics
CHPL_GMP: none
CHPL_HWLOC: hwloc
CHPL_REGEXP: re2
CHPL_WIDE_POINTERS: struct
CHPL_AUX_FILESYS: none
chpl Version 1.15.0
Copyright (c) 2004-2017, Cray Inc. (See LICENSE file for more details)
$ clang --version
Apple LLVM version 8.1.0 (clang-802.0.42)
Target: x86_64-apple-darwin16.6.0
Thread model: posix
InstalledDir:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Am I doing something silly - is there another, better way to deal with arrays
of non-fixed sizes?
Best,
Jonathan
ragged_associative_array.chpl
Description: Binary data
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________ Chapel-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/chapel-users
