Skip to content

Instantly share code, notes, and snippets.

@mppf
mppf / a.d
Created June 20, 2017 14:19
D lang array resize pointer safety example
/* compile with ldc2 a.d */
module a;
import std.stdio;
@safe
int main()
{
int[] array;
array.length = 7;
record R {
var x: int;
proc deinit() {
writeln("Destroying ", x);
}
}
proc foo() {
var count = 0;
@mppf
mppf / order-independent-vs-loop-carried.chpl
Last active July 7, 2017 18:34
order independent vs loop carried
var sum: int;
for i in vectorizeOnly(1..n) {
sum += i; // is sum "order independent" ? Is there a loop-carried dependency to respect?
// say it turns in to
// %1 = load %sum
// %2 = add %1, i
// store %2, %sum
// would it be wrong to assert there is no loop-carried dependency?
}
#include <stdio.h>
void setit(int* ptr) {
*ptr = 200;
}
void f(int x) {
printf("%i\n", x);
}
@mppf
mppf / Bug.chpl
Last active July 21, 2017 17:18
showing bug with implicit module and same name inner module
proc bar() {
writeln("in bar");
}
module Bug {
proc foo() {
writeln("in foo");
}
}
proc testOnBegin() {
sync {
on Locales[numLocales-1] do begin {
writeln("HERE");
}
}
}
testOnBegin();
@mppf
mppf / jt.chpl
Created August 10, 2017 14:52
Example of reading JSON with a Chapel class
class Fighter {
var subclass:string;
var level:int;
}
var mem = openmem();
var writer = mem.writer().write('{"subclass":"ninja", "level":3}');
var reader = mem.reader();
// This works
module OtherMSBRadix {
use Shell;
use Time;
/* Sorting criterion has a method:
(key:uint,done:bool) = criterion.keyBits(record, startbit)
(cmp=-1,0,1,nsamebits) = criterion.prefixCompare(recordA, recordB)
cmp=-1,0,1 = criterion.compare(recordA, recordB)
@mppf
mppf / spec.rst
Created September 23, 2019 19:31

©2019 Cray Inc.

Scope

[Scope]

Chapel is a new parallel programming language that is under development at Cray Inc. in the context of the DARPA High Productivity Computing Systems initiative.

@mppf
mppf / dp-m2.chpl
Created May 17, 2020 11:34
variants on dp question
// shows program modified to avoid array views in inner loops
class AbstractKernel {
// assumes x[xfirst, ..] and y[yfirst, ..] have shape 1..p
proc kernel(x, xfirst: int, y: [?D] ?T, yfirst: int, p: int): T
{
return x[xfirst, 0]; // out of bounds (intentionally?)
}
}