chapel

Good practice to hold a file or channel in a class

不想你离开。 提交于 2019-12-11 03:52:07
问题 In the following code, I am trying to make a class which can write something to a log file when asked via a method. Here, I am wondering if this is an idiomatic way for this purpose, or possibly is there a more recommended way, e.g., hold a separate field of file type (for some reason)? In other words, is it pratically no problem even if I hold only a channel type? class Myclass { var logfile: channel; proc init() { writeln( "creating log.out" ); logfile = openwriter( "log.out" ); } proc log(

Create domain with matrices in Chapel

假装没事ソ 提交于 2019-12-11 03:07:52
问题 I have a domain D , and I want to use it to index several matrices A . Something of the form var dom: domain(1) = {0..5}; var mats: [dom] <?>; var a0 = [[0.0, 0.1, 0.2], [0.3, 0.4, 0.5]]; var a1 = [[1.0, 1.1, 1.2, 1.3], [1.4, 1.5, 1.6, 1.7]]; mats[0] = a0; mats[1] = a1; Each a will be 2D but have different sizes. Yes, some of these will be sparse (but need not be for purposes of this question) == UPDATE == For clarity, I have a series of layers (it's a neural net), say 1..15. I created var

Whether loop variables are always freshly created

故事扮演 提交于 2019-12-11 02:42:47
问题 In the following code, I'm using the variable name n for both a local variable and a loop counter: proc main() { var n = 700; writeln( "n (before loop) = ", n ); for n in 1..3 { writeln( "n = ", n ); } writeln( "n (after loop) = ", n ); } and the result is n (before loop) = 700 n = 1 n = 2 n = 3 n (after loop) = 700 Does this mean that the for loop always creates a new loop variable, in a way similar to for (int n = 1; n <= 3; n++) rather than for (n = 1; n <= 3; n++) (in C-like languages)?

How to iterate non-zeroes in a sparse matrix in Chapel

帅比萌擦擦* 提交于 2019-12-08 15:42:28
I have a matrix A still hanging around. It's large, sparse and new symmetric. I've created a sparse domain called spDom that contains the non-zero entries. Now, I want to iterate along row r and find the non-zero entries there, along with the index. My goal is to build another domain that is essentially row r 's non-zeroes. Here's an answer that will work with Chapel 1.15 as long as you're willing to store your sparse domain/array in CSR format: First, I'll establish my (small, non-symmetric) sparse matrix for demonstration purposes: use LayoutCS; // use the CSR/CSC layout module config const

How to iterate non-zeroes in a sparse matrix in Chapel

允我心安 提交于 2019-12-08 08:47:38
问题 I have a matrix A still hanging around. It's large, sparse and new symmetric. I've created a sparse domain called spDom that contains the non-zero entries. Now, I want to iterate along row r and find the non-zero entries there, along with the index. My goal is to build another domain that is essentially row r 's non-zeroes. 回答1: Here's an answer that will work with Chapel 1.15 as long as you're willing to store your sparse domain/array in CSR format: First, I'll establish my (small, non

Calculate rowSums in Chapel for a matrix

给你一囗甜甜゛ 提交于 2019-12-07 16:06:53
问题 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? 回答1: 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 =

Slowdown of pi calculation when Timer is used

一曲冷凌霜 提交于 2019-12-07 10:17:07
问题 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

Include second source file in Chapel file

妖精的绣舞 提交于 2019-12-07 08:06:02
问题 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? 回答1: 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,

Is it possible to declare an array with config?

空扰寡人 提交于 2019-12-07 05:35:45
问题 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

How do dmapped domains in chapel language get actually mapped onto?

半城伤御伤魂 提交于 2019-12-06 11:52:17
问题 I need to know few things about array element allocation over domain map in chapel Let me keep this as short as possible region = {1..10,5..10} regionbox = {1..5,1..5} grid2d = /*a 2D arrangement of locales*/ Space = domain(2) dmapped Block( boundingBox = regionbox, target_locales = grid2d ) = region. var : myarray[Space] int; Now Space is a distributed domain. So here comes in. In a distributed domain, whether we have to keep all our indexes in each locality that is For the above example.