Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JG1VPP committed Jan 14, 2023
0 parents commit cc3684e
Show file tree
Hide file tree
Showing 78 changed files with 475 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.*
!.gitignore
29 changes: 29 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2022, Journal of Hamradio Informatics
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Tutorial: Chapel the Parallel Programming Language
====

![image](https://img.shields.io/badge/Chapel-1.28-red.svg)
![image](https://img.shields.io/badge/license-BSD%203--Clause-darkblue.svg)

[うさぎさんでもわかる並列言語Chapel (PDF)](https://nextzlog.dev/chpl.pdf) [(HTML)](https://nextzlog.dev/chpl)

## Contribution

Feel free to make issues at [nextzlog/todo](https://github.com/nextzlog/todo).
Follow [@nextzlog](https://twitter.com/nextzlog) on Twitter.

## License

### Author

[無線部開発班](https://nextzlog.dev)

### Clauses

[BSD 3-Clause License](LICENSE.md)
18 changes: 18 additions & 0 deletions chapter1/baz.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Foo {
writeln("initilize Foo");
proc main() {
writeln("This is Foo");
}
}
module Bar {
writeln("initilize Bar");
proc main() {
writeln("This is Bar");
}
}
import baz.Foo;
import baz.Bar;
proc main() {
Foo.main();
Bar.main();
}
5 changes: 5 additions & 0 deletions chapter1/hello.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
multiline comments
or block comments
*/
writeln("Hello, world!"); // 1-line comments
2 changes: 2 additions & 0 deletions chapter2/cast.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
writeln(1 + 2: real); // 3.0
writeln(int: string); // int(64)
3 changes: 3 additions & 0 deletions chapter2/reduce.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
writeln(+ scan(1..10)); // 1 3 6 10 15 21 28 36 45 55
writeln("value, index: ", minloc reduce zip([3, 2, 1], 0..2)); // value, index: (1, 2)
writeln("value, index: ", maxloc reduce zip([4, 5, 6], 0..2)); // value, index: (6, 2)
4 changes: 4 additions & 0 deletions chapter3/config.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config param foo = 121;
config const bar = 121;
config type num = uint;
writeln(foo, bar, num: string);
2 changes: 2 additions & 0 deletions chapter3/const.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const foo: int = 12;
const bar = 12;
3 changes: 3 additions & 0 deletions chapter3/param.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
param foo: int = 12;
param bar = 12;
type num = int;
7 changes: 7 additions & 0 deletions chapter3/types.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
param a: bool = true;
param b: uint = 1919;
param c: real = 8.10;
param d: imag = 364i;
param e: string = 'ABC' + "DEF";
param f: Gibier = Gibier.Rabbit;
enum Gibier {Deer, Boar, Rabbit};
7 changes: 7 additions & 0 deletions chapter3/var.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var foo: int = 12;
var bar: int;
foo = 889464;
var a = "golden axe.";
var b = "silver axe.";
a <=> b;
writeln(a, b, foo);
3 changes: 3 additions & 0 deletions chapter4/break.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
while true do break;
for 1..100 do continue;
label outside for i in 1..10 do for j in 1..10 do break outside;
1 change: 1 addition & 0 deletions chapter4/for.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
for i in 1..100 do writeln(i);
6 changes: 6 additions & 0 deletions chapter4/if.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const age = 18;
if age < 18 then {
writeln("Adults Only");
} else {
writeln("Yeah, Right");
}
6 changes: 6 additions & 0 deletions chapter4/scope.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
var foo = 12;
writeln(foo);
}
var foo = 13;
writeln(foo);
5 changes: 5 additions & 0 deletions chapter4/select.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
select "cat" {
when "cat" do writeln("meow");
when "dog" do writeln("bowwow");
otherwise writeln("gobblegobble");
}
4 changes: 4 additions & 0 deletions chapter4/while.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var i = 1;
while i < 1024 do i *= 2;
do i >>= 1; while i >= 1;
writeln(i); // 0
4 changes: 4 additions & 0 deletions chapter5/default.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
proc foo(x: int = 0, y: int = 0): int return x + y;
writeln(foo(x = 1, y = 2)); // 3
writeln(foo(y = 2, x = 1)); // 3
writeln(foo(1)); // 1
3 changes: 3 additions & 0 deletions chapter5/fact.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
proc fact(param n: int) param: int where n >= 1 return n * fact(n-1);
proc fact(param n: int) param: int where n == 0 return 1;
if fact(8) != 5040 then compilerError("fact(7) == 5040");
3 changes: 3 additions & 0 deletions chapter5/infer.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
proc foo(x, y) return x + y;
writeln(foo(1, 2i)); // 1 + 2i
writeln(foo(2i, 3)); // 3 + 2i
4 changes: 4 additions & 0 deletions chapter5/inline.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
inline proc foo(x: int): int return 2 * x;
export proc bar(x: int): int return 2 * x;
writeln(foo(100)); // 200
writeln(bar(300)); // 600
11 changes: 11 additions & 0 deletions chapter5/intent.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
proc intents(inout x: int, in y: int, out z: int, ref v: int): void {
x += y;
z += y;
v += y;
}
var a: int = 1;
var b: int = 2;
var c: int = 3;
var d: int = 4;
intents(a, b, c, d);
writeln(a, b, c, d); // 3226
11 changes: 11 additions & 0 deletions chapter5/iter.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
iter iterator(): string {
yield "EMURATED";
yield "EMURATED";
yield "EMURATED";
}
iter int.these() const ref: int {
for i in 1..this do yield i;
}
var repetition: int = 10;
for i in iterator() do writeln(i);
for i in repetition do writeln(i);
3 changes: 3 additions & 0 deletions chapter5/lambda.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
proc call(f, x: int, y: int): int return f(x, y);
const add = lambda(x: int, y: int) return x + y;;
writeln(call(add: func(int, int, int), 36, 514)); // 550
4 changes: 4 additions & 0 deletions chapter5/lvalue.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var tuple = (0, 0, 0, 0, 0, 0, 0, 0, 0);
proc A(i: int) ref: int return tuple(i);
coforall i in tuple.indices do A(i) = i;
writeln(tuple);
2 changes: 2 additions & 0 deletions chapter5/name.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proc foo return 100110;
writeln(foo);
8 changes: 8 additions & 0 deletions chapter5/nest.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
proc factorial(num: int): int {
proc tc(n, accum: int): int {
if n == 0 then return accum;
return tc(n - 1, n * accum);
}
return tc(num, 1);
}
writeln(factorial(10)); // 3628800
2 changes: 2 additions & 0 deletions chapter5/operator.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
operator *(text: string, num: int) return + reduce (for 1..num do text);
writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit" * 10);
2 changes: 2 additions & 0 deletions chapter5/param.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proc tuplet(param dim: int, type eltType) type return dim * eltType;
const septet: tuplet(7, int) = (114, 514, 1919, 810, 364, 889, 464);
4 changes: 4 additions & 0 deletions chapter5/proc.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
proc foo(x: int, y: int): int {
return x + y;
}
writeln(foo(1, 2));
6 changes: 6 additions & 0 deletions chapter5/query.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
proc foo(x: [?dom] ?el) return (dom, el: string);
proc bar(x) return (x.domain, x.eltType: string);
writeln(foo([1, 2, 3, 4, 5, 6, 7, 8])); // ({0..7}, int(64))
writeln(bar([1, 2, 3, 4, 5, 6, 7, 8])); // ({0..7}, int(64))
writeln(foo(["one" => 1, "two" => 2])); // ({one, two}, int(64))
writeln(bar(["one" => 1, "two" => 2])); // ({one, two}, int(64))
3 changes: 3 additions & 0 deletions chapter5/sched.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "sched.h";
extern proc sched_getcpu(): int;
writeln("CPU:", sched_getcpu());
1 change: 1 addition & 0 deletions chapter5/sched.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int sched_getcpu();
10 changes: 10 additions & 0 deletions chapter5/throw.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
proc foo(message: string) throws {
defer writeln("See you");
throw new Error(message);
}
try {
foo("Hello,");
foo("world!");
} catch e {
writeln(e);
}
2 changes: 2 additions & 0 deletions chapter5/varargs.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
proc sum(x: int ...): int return + reduce(x);
writeln(sum(1, 2, 3) + sum((...(100, 200)))); // 306
6 changes: 6 additions & 0 deletions chapter5/where.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
proc whichType(x: ?xt): string where xt == real return "x is real";
proc whichType(x: ?xt): string where xt == imag return "x is imag";
proc whichType(x: ?xt): string return "x is neither real nor imag";
writeln(whichType(114.514));
writeln(whichType(364364i));
writeln(whichType(1919810));
10 changes: 10 additions & 0 deletions chapter6/accessor.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
record User {
var name: string;
}
proc User.name ref {
writeln(".name");
return this.name;
}
var user: User;
user.name = "Jane";
writeln(user.name);
9 changes: 9 additions & 0 deletions chapter6/deinit.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Sub {
const x: real = 0;
const y: real = 0;
proc deinit() {
writeln("deleted");
}
}
const sub = new Sub(x = 1, y = 2);
writeln("x, y: ", (sub.x, sub.y));
9 changes: 9 additions & 0 deletions chapter6/duck.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Duck {
proc quack() return "quack!";
}
class Kamo {
proc quack() return "quack!";
}
proc voice(x) return x.quack();
writeln(voice(new Duck())); // quack!
writeln(voice(new Kamo())); // quack!
8 changes: 8 additions & 0 deletions chapter6/generics.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
record Stack {
type eltType;
param size: int;
}
var a: Stack(eltType = uint, size = 12);
var b: Stack(eltType = real, size = 24);
writeln("a is ", a.type: string); // a is Stack(uint(64), 12)
writeln("b is ", b.type: string); // b is Stack(real(64), 24)
10 changes: 10 additions & 0 deletions chapter6/inherit.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Foo {
proc foo() return "foo!";
}
class Bar: Foo {
override proc foo() return super.foo() + "bar!";
}
const foo = new Foo();
const bar = new Bar();
writeln(foo.foo()); // foo!
writeln(bar.foo()); // foo!bar!
10 changes: 10 additions & 0 deletions chapter6/init.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Add {
const x: real;
const y: real;
proc init(x, y) {
this.x = x;
this.y = y;
}
}
const add = new Add(x = 1, y = 2);
writeln("x, y: ", (add.x, add.y));
9 changes: 9 additions & 0 deletions chapter6/method.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
record User {
var name: string;
proc set(name) {
this.name = name;
}
}
var user: User;
user.set("Alicia");
writeln(user.name);
8 changes: 8 additions & 0 deletions chapter6/num1.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Num {
var r: real;
var i: imag;
}
var num: Num = new Num();
num.r = 816.07;
num.i = 14.22i;
writeln(num.r);
8 changes: 8 additions & 0 deletions chapter6/num2.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
record Num {
var r: real;
var i: imag;
}
var num: Num;
num.r = 816.07;
num.i = 14.22i;
writeln(num.r);
8 changes: 8 additions & 0 deletions chapter6/num3.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
union Num {
var r: real;
var i: imag;
}
var num: Num;
num.r = 816.07;
num.i = 14.22i;
writeln(num.i);
7 changes: 7 additions & 0 deletions chapter6/owned.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Hello {
proc deinit() {
writeln("See you");
}
}
var hello: owned Hello = new owned Hello();
var hallo: borrowed Hello = hello.borrow();
7 changes: 7 additions & 0 deletions chapter6/shared.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Hello {
proc deinit() {
writeln("See you");
}
}
var hello = new shared Hello();
var hallo = new unmanaged Hello();
5 changes: 5 additions & 0 deletions chapter6/this.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Add {
proc this(a: int, b: int): int return a + b;
}
const add = new Add();
writeln(add(123, 45)); // 168
4 changes: 4 additions & 0 deletions chapter7/array.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const rectangular = [1, 2, 3, 4, 5, 6, 7, 8];
const associative = [1 => "one", 2 => "two"];
writeln(rectangular, rectangular.domain); // 1 2 3 4 5 6 7 8{0..7}
writeln(associative, associative.domain); // one two{1, 2}
3 changes: 3 additions & 0 deletions chapter7/by.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
writeln(10..30 by -7); // 30 23 16
writeln(10..30 by -7 align 13); // 27 20 13
writeln(10..30 by -7 align 13 # 2); // 27 20
6 changes: 6 additions & 0 deletions chapter7/domain.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const rectangular: domain = {0..10, -1..2};
const associative: domain = {"foo", "bar"};
writeln(rectangular.rank);
writeln(rectangular.dims());
writeln(rectangular.idxType: string); // int(64)
writeln(associative.idxType: string); // string
3 changes: 3 additions & 0 deletions chapter7/for.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
for i in 1..100 do writeln(i);
forall i in 1..100 do writeln(i);
coforall i in 1..100 do writeln(i);
2 changes: 2 additions & 0 deletions chapter7/loops.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
for xyz in {1..10, 1..10, 1..10} do writeln(xyz);
for boy in {"Tom", "Ken", "Bob"} do writeln(boy);
Loading

0 comments on commit cc3684e

Please sign in to comment.