Reputation: 23
Consider this code:
proc generateTuples(a: int, b: int, bNext: int): [] {
var tuples: [1..?] (int,int);
for q in (b+1)..(bNext-1) {
tuples.push([a, q]);
}
return tuples;
}
proc mergeLists(l1: [(int,int)], l2: [(int,int)]): [(int,int)] {
var result: [1..?](int,int);
var i1:int = 1;
var i2:int = 1;
while ((i1 <= l1.size) && (i2 <= l2.size)) {
if l1[i1] < l2[i2] {
result.push(l1[i1]);
i1 += 1;
} else {
result.push(l2[i2]);
i2 = i2+1;
}
}
result.append(l1[i1..l1.size]);
result.append(l2[i2..l2.size]);
return result;
}
proc generateTuplesSub(L: [1..?](int,int), start: int, end: int): [] (int,int) {
writeln(start," ",end);
if end <start {
var b: [1..0] (int,int);
return b;
}
var mid: int = (start + end) / 2;
var aMid = L[mid][0];
var bMid = L[mid][1];
var tuplesLeft = generateTuplesSub(L, start, mid);
var tuplesRight = generateTuplesSub(L, mid, end);
// Merge the tuples generated for the left and right halves
var result = mergeLists(tuplesLeft, tuplesRight);
// Add the tuples generated for the (aMid, bMid) pair
if mid < end - 1 {
var bNext = L[mid+1][1];
var tuplesMid = generateTuples(aMid, bMid, bNext);
result = mergeLists(result, tuplesMid);
}
return result;
}
// Example usage
var L = [(0, 4), (1, 5), (2, 6), (3, 7), (4, 8), (5, 10), (6, 12)];
var numProcesses = L.size;
var result = generateTuplesSub(L, 1,7);
for tup in result {
writeln("(", tup[1], ", ", tup[2], ")");
}
It is written in Chapel programming language. I get the following error:
called as generateTuplesSub(L: [domain(1,int(64),false)] 2*int(64), start: int(64), end: int(64))
note: generic instantiations are underlined in the above callstack.
What does it mean? What should I do? I am compiling in with terminal of Mac. It looks like that there is a problem with the input type, but I do not understand it.
I get error when I want to compile it.
Upvotes: 0
Views: 58
Reputation: 4043
When I compile your code with Chapel version 1.29, I get a similar but different error:
/ATO/code.chpl:27: In function 'generateTuplesSub':
/ATO/code.chpl:27: error: Ranges defined using bounds of type 'int(64).._uninstantiated' are not currently supported
/ATO/code.chpl:58: called as generateTuplesSub(L: [domain(1,int(64),false)] 2*int(64), start: int(64), end: int(64))
yargs: execvp: No such file or directory
Though neither error is terribly clear, I believe that the source of both is the expression 1..?
which is not currently supported by Chapel (though we'd like it, or something like it, to be in certain contexts). For formal arguments to procedures, like the one on line 27 where this appears, you can just leave out the array's indices, and they will be inferred by the compiler.
Looking through the rest of your code, I'm seeing other differences which suggest to me that you may be either using a much older version of Chapel or possibly referring to outdated Chapel documentation or examples?
Working through other compiler errors I saw with 1.29:
generateTuplesSub()
can't be inferred because it's a recursive procedure. Unfortunately, this is a case where Chapel can't infer the array's indices, so I think you'll need to put in something explicit (where my best guess was that [1..<end-start]
might be correct, or nearly correct?)[1..?]
will similarly need to be given sizes, either by pre-computing the size and using it directly in the declaration (which it looks to me like you should be able to do in these cases?) or else by declaring a named domain variable and resizing it as necessary (which is more complex and expensive if you can compute the size accurately).push()
and .append()
routines, so you'll need to rewrite those operations to keep track of the next index where data should be stored in the array. Alternatively you could switch to the List data type which does support those kinds of operations[(int,int)]
where I think you want [] (int, int)
(or possibly [lo..hi] (int, int)
, for some value of lo
and hi
)?tuples.push([a, q])
, [a, q]
is a 2-element array, where I think you want a 2-element tuple, so should write (a, q)
Making these changes, I was able to get a program that compiled, but which almost certainly didn't compute the right answer (but almost certainly because I made a mistake in guessing what you were doing). I'd suggest updating to Chapel 1.29 if you're using an older version and seeing if you can work through the similar series of changes I outline above, but making fewer mistakes than I probably did in my copy.
Upvotes: 2