chapel

When should I use a Record vs a Class in Chapel

爱⌒轻易说出口 提交于 2021-02-08 16:59:27
问题 When is it advantageous to use Record type vs a Class in Chapel? On IRC someone mentioned that Records distribute over locales better or something. 回答1: Records and classes are similar in Chapel in that they both support the creation of objects with fields and methods. That said, there are some major differences as well . Here's a quick review of some of those differences ( tl;dr: records are roughly like C structs while classes support class hierarchies, dynamic dispatch, etc.), followed by

Distribute 2D array row wise among Locales in Chapel

我与影子孤独终老i 提交于 2020-08-27 09:02:18
问题 I am learning Chapel and have worked with blockdist but I can't figure out how can I distribute a 2-dimension array in row wise fashion among locales. 回答1: The key is to pass a reshaped Locales array as the targetLocales argument to Block . This is explained further below. Here's a simple example of distributing a 2D array in a row-wise fashion: use BlockDist; // Using a 2D targetLocales rather than the default 1D Locales argument var targetLocales = reshape(Locales, {0..#numLocales, 0..0});

How to append a sparse domain in Chapel

浪尽此生 提交于 2020-01-02 08:47:51
问题 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! 回答1: The way you show in the snippet will expand the internal arrays of

How to check subclass in Chapel

跟風遠走 提交于 2020-01-01 19:14:34
问题 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. 回答1: For an exact type match, you

How to check subclass in Chapel

 ̄綄美尐妖づ 提交于 2020-01-01 19:14:03
问题 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. 回答1: For an exact type match, you

Optional function arguments with no default value possible?

大兔子大兔子 提交于 2019-12-24 06:49:05
问题 In Chapel, we can set the default value of function formal arguments easily, for example, proc test( a = 1, b = 2.0, c = "hi" ) { ... } and call the function by using keywords also: test( 10 ); // a = 10, b = 2.0, c = "hi" test( b = 3.14 ); // a = 1, b = 3.14, c = "hi" test( c = "yo" ); // a = 1, b = 2.0, c = "yo" Here, I am wondering if it is possible to define a keyword argument that does not require a predefined default value. More specifically, I would like to write a function that can

Fine grain control over rows distribution among locales in multi-locale program in Chapel

喜欢而已 提交于 2019-12-23 12:16:33
问题 I am trying to implement an SOR, successive over relaxation, program in Chapel for multi-locale, but with local memory so I want to distribute rows among the locales explicitly. I already have reshaped targetlocales to 1D, but now I am not sure how I can have control over the rows distribution among the locales. I am very much used to MPI so I will give an example of what I want to achieve in accordance to MPI. Is there a way I can specify that I want to distribute all the array rows among

While loop in a method gets stuck. Adding an assignment of a field to itself fixes the issue

折月煮酒 提交于 2019-12-23 10:46:11
问题 Starting our Semaphore project, I gave my students a bad version of the p() method: proc p() { while (this.tokens <= 0) { sleep(1); writeln("Tokens: ", this.tokens); } this.tokens -= 1; } I give them some additional code to test it which increments the number of tokens (using the v() method) in another thread. You can see the number of tokens increasing (above 0) but the code does not exit the while loop. On a whim, I added an assignment statement: proc p() { while (this.tokens <= 0) { this

CyclicDist goes slower on multiple locales

孤者浪人 提交于 2019-12-22 14:48:06
问题 I tried doing an implementation of Matrix multiplication using CyclicDist module. When I test with one locale vs two locales, the one locale is much faster. Is it because the time to communicate between the two Jetson nano boards is really big or is my implementation not taking advantage of the way CyclicDist works? Here is my code: use Random, Time, CyclicDist; var t : Timer; t.start(); config const size = 10; const Space = {1..size, 1..size}; const gridSpace = Space dmapped Cyclic(startIdx

How to specify a return of an array of unknown size in Chapel

谁说我不能喝 提交于 2019-12-11 08:54:28
问题 I tried to rely on type inference for a function with signature: proc mode(data: [?]int) but the compiler said it could not resolve the return type (which is a warning in in itself I guess given there are only two return statements). I tried: proc mode(data: [?]int): [?]int but the compiler then said there was an internal error: internal error: CAL0057 chpl Version 1.13.1.518d486 What is the correct way of specifying that the length of an array returned by a function can only be known at run