chapel

Calculate rowSums in Chapel for a matrix

独自空忆成欢 提交于 2019-12-06 02:14:57
Continuing my Chapel adventures... I have a matrix A. var idx = {1..n}; var adom = {idx, idx}; var A: [adom] int; //populate A; var rowsums: [idx] int; What is the most efficient way to populate rowsums? The most efficient solution is hard to define. However, here is one way to compute rowsums that is both parallel and elegant: config const n = 8; // "naked" n would cause compilation to fail const indices = 1..n; // tio.chpl:1: error: 'n' undeclared (first use this function) const adom = {indices, indices}; var A: [adom] int; // Populate A [(i,j) in adom] A[i, j] = i*j; var rowsums: [indices]

How to append a sparse domain in Chapel

谁都会走 提交于 2019-12-05 20:11:04
I'm populating a sparse array in Chapel with a loop that is reading over a CSV. I'm wondering what the best pattern is. var dnsDom = {1..n_dims, 1..n_dims}; var spsDom: sparse subdomain(dnsDom); for line in file_reader.lines() { var i = line[1]:int; var j = line[2]:int; spsDom += (i,j); } Is this an efficient way of doing it? Should I create a temporary array of tuples and append spsDom every ( say ) 10,000 rows? Thanks! The way you show in the snippet will expand the internal arrays of the sparse domain at every += operation. As you suggested; somehow buffering the read indices, then adding

Include second source file in Chapel file

巧了我就是萌 提交于 2019-12-05 16:27:37
In C++, when I need classes in 'actions.cpp' from classes.cpp I include the header, like #include <classes.h> . But trying use classes.chpl fails, is there a .h equivalent I should be using? Use is only for module names, not full file names. If your file classes.chpl does not have an explicit module enclosing its entire contents, then you would type use classes; in order to access its contents from another file. If classes.chpl is in the same directory as the file with the use statement, that should be all that is necessary to access its symbols. If classes.chpl is in a different directory,

Slowdown of pi calculation when Timer is used

北慕城南 提交于 2019-12-05 14:43:58
The following code is my code for calculating pi = 3.1415... approximately using this formula: use Time; var timer = new Timer(); config const n = 10**9; var x = 0.0, s = 0.0; // timer.start(); // [1]_____ for k in 0 .. n { s = ( if k % 2 == 0 then 1.0 else -1.0 ); // (-1)^k x += s / ( 2.0 * k + 1.0 ); } // timer.stop(); // [2]_____ // writeln( "time = ", timer.elapsed() ); // [3]_____ writef( "pi (approx) = %30.20dr\n", x * 4 ); // writef( "pi (exact) = %30.20dr\n", pi ); // [4]_____ When the above code is compiled as chpl --fast test.chpl and executed as time ./a.out , then it runs with ~4

Is it possible to declare an array with config?

99封情书 提交于 2019-12-05 11:30:07
Or any similar data structure of dynamic length, which, can be cast easily to an array. The only workaround I have found is entering the array as a string and manually parsing it. config var not_array: string = '[1,2,3,4,5]' ; proc main() { // config array workaround writeln("I am string. Definitely not array ", not_array) ; // parse string not_array = not_array.replace(' ','') ; not_array = not_array.replace('[','') ; not_array = not_array.replace(']','') ; var still_not_array = not_array.split(',') ; // prepare array var dom = 0..#still_not_array.size ; var array: [dom] real ; // populate

How Domain maps map indexes to target locales array in multi-dimension case

孤人 提交于 2019-12-05 03:50:48
问题 I didn't find how the domain map maps the indices in the multi-dimensional domains to the multi-dimensional target locales. 1.) How the target locales (one dimension) is arranged in multi-dimension fashion which equals the distribution dimension to map the indexes? 2.) In documentation it states that for multi-dimension case, the computation should be done in every dimension. For the domain {1..8, 1..8} ==> dom assume dom is block-distributed over 6 target locales. Steps in mapping 1 for 1st

How to check subclass in Chapel

淺唱寂寞╮ 提交于 2019-12-04 19:26:45
This one is probably really stupid. How do you check the subclass of an object in Chapel? class Banana : Fruit { var color: string; } class Apple: Fruit { var poison: bool; } class Fruit { } var a = new Apple(poison=true); var b = new Banana(color="green"); // ?, kinda Java-ish, what should I do? if (type(a) == Apple.class()) { writeln("Go away doctor!"); } Though I'm asking about a subclass, I realize I don't know how to check if it's a Fruit class either. For an exact type match, you will want to write this: if (a.type == Apple) { writeln("Go away doctor!"); } To check if the type of a is a

Use Chapel to handle massive matrix

心不动则不痛 提交于 2019-12-04 01:38:46
问题 I've recently come across Chapel and I'm very keen to try it out. I have a two-fold problem I'm hoping it can solve. I typically work in Python or C++. Java when backed into a corner. I have two matrices I and V . Both are sparse and of dimension about 600K x 600K, populated at about 1% density. First, using SciPy, I can load both from a SQL database into memory at the moment. However, I expect our next iteration will be simply too large for our machines. Perhaps 1.5M^2. In a case like that,

How Domain maps map indexes to target locales array in multi-dimension case

[亡魂溺海] 提交于 2019-12-03 21:39:48
I didn't find how the domain map maps the indices in the multi-dimensional domains to the multi-dimensional target locales. 1.) How the target locales (one dimension) is arranged in multi-dimension fashion which equals the distribution dimension to map the indexes? 2.) In documentation it states that for multi-dimension case, the computation should be done in every dimension. For the domain {1..8, 1..8} ==> dom assume dom is block-distributed over 6 target locales. Steps in mapping 1 for 1st dimension (1..8) do the computation if idx is low<=idx<=high then locid is floor (idx-low)*N / (high

Is `[<var> in <distributed variable>]` equivalent to `forall`?

狂风中的少年 提交于 2019-12-01 19:03:53
问题 I noticed something in a snippet of code I was given: var D: domain(2) dmapped Block(boundingBox=Space) = Space; var A: [D] int; [a in A] a = a.locale.id; Is [a in A] equivalent to forall a in A a = a.locale.id ? 回答1: Yes, exactly. In Chapel, [a in A] expr is equivalent to forall a in A do expr . With respect to the title of this question, note that this is independent of whether or not A is distributed. For example, you could also write [i in 1..n] rather than forall i in 1..n do . Array