mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Update Chapel samples.
This commit is contained in:
@@ -58,6 +58,34 @@ var BA: [BlockSpace] int;
|
|||||||
forall ba in BA do
|
forall ba in BA do
|
||||||
ba = here.id;
|
ba = here.id;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The 'hasSingleLocalSubdomain' method on arrays will return true if the
|
||||||
|
// index set for a locale can be represented by a single domain.
|
||||||
|
//
|
||||||
|
if !BA.hasSingleLocalSubdomain() then
|
||||||
|
halt("For a Block distribution, the index set per locale should be \
|
||||||
|
represented by a single domain");
|
||||||
|
|
||||||
|
//
|
||||||
|
// If the distribution's subdomains can be represented as single subdomain,
|
||||||
|
// we can use the 'localSubdomain' method to get the index set for the
|
||||||
|
// current locale.
|
||||||
|
//
|
||||||
|
// Below, we'll use the index set to confirm that the array elements have the
|
||||||
|
// correct locale id.
|
||||||
|
//
|
||||||
|
|
||||||
|
for L in Locales {
|
||||||
|
on L {
|
||||||
|
const indices = BA.localSubdomain();
|
||||||
|
for i in indices {
|
||||||
|
if BA[i] != L.id then
|
||||||
|
halt("Error: incorrect locale id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Output the Block-distributed array to visually see how the elements
|
// Output the Block-distributed array to visually see how the elements
|
||||||
// are partitioned across the locales.
|
// are partitioned across the locales.
|
||||||
@@ -104,6 +132,14 @@ writeln("Block Array Index Map");
|
|||||||
writeln(BA2);
|
writeln(BA2);
|
||||||
writeln();
|
writeln();
|
||||||
|
|
||||||
|
//
|
||||||
|
// We can use the 'targetLocales' method available on an array to get the
|
||||||
|
// locales array used as targets.
|
||||||
|
//
|
||||||
|
for (L, ML) in zip(BA2.targetLocales(), MyLocales) do
|
||||||
|
if L != ML then
|
||||||
|
halt("Error: BA2.targetLocales() should equal MyLocales");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -126,6 +162,18 @@ writeln("Cyclic Array Index Map");
|
|||||||
writeln(CA);
|
writeln(CA);
|
||||||
writeln();
|
writeln();
|
||||||
|
|
||||||
|
//
|
||||||
|
// The domain returned by 'localSubdomain' need not be a dense block, as is
|
||||||
|
// the case for the Cyclic Distribution.
|
||||||
|
//
|
||||||
|
on Locales[0] {
|
||||||
|
const indices = CA.localSubdomain();
|
||||||
|
for i in indices {
|
||||||
|
if CA[i] != 0 then
|
||||||
|
halt("Error: Cyclic array values on Locale 0 should be zero");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Next, we'll declare a Block-Cyclic distribution. These
|
// Next, we'll declare a Block-Cyclic distribution. These
|
||||||
@@ -146,6 +194,46 @@ writeln("Block-Cyclic Array Index Map");
|
|||||||
writeln(BCA);
|
writeln(BCA);
|
||||||
writeln();
|
writeln();
|
||||||
|
|
||||||
|
//
|
||||||
|
// A locale's index set for a Block-Cyclic distribution cannot be represented
|
||||||
|
// by a single subdomain.
|
||||||
|
//
|
||||||
|
if BCA.hasSingleLocalSubdomain() then
|
||||||
|
halt("A Block-Cyclic index set cannot be represented by a single subdomain");
|
||||||
|
|
||||||
|
//
|
||||||
|
// If the local index set cannot be represented by a single subdomain,
|
||||||
|
// we can use the 'localSubdomains' iterator to yield a number of domains
|
||||||
|
// that represent the whole index set.
|
||||||
|
//
|
||||||
|
// Let's write a function that will use 'localSubdomains' to verify the
|
||||||
|
// correctness of the array values.
|
||||||
|
//
|
||||||
|
|
||||||
|
proc verifyID(Data: []) {
|
||||||
|
for L in Locales {
|
||||||
|
on L {
|
||||||
|
for indices in Data.localSubdomains() {
|
||||||
|
for i in indices {
|
||||||
|
if Data[i] != L.id then
|
||||||
|
halt("Error: incorrect locale id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
verifyID(BCA);
|
||||||
|
|
||||||
|
//
|
||||||
|
// The 'localSubdomains' iterator is also available on distributions that
|
||||||
|
// can represent a locale's index set with a single domain. This allows us to
|
||||||
|
// write more general code that will work for all distributions.
|
||||||
|
//
|
||||||
|
// This means that we can call the 'verifyID' function on any array, like the
|
||||||
|
// 'BA' array from earlier.
|
||||||
|
//
|
||||||
|
verifyID(BA);
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// The ReplicatedDist distribution is different: each of the
|
// The ReplicatedDist distribution is different: each of the
|
||||||
|
|||||||
@@ -292,14 +292,14 @@ proc main() {
|
|||||||
LagrangeLeapFrog();
|
LagrangeLeapFrog();
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
// deprint("[[ Forces ]]", fx, fy, fz);
|
deprintatomic("[[ Forces ]]", fx, fy, fz);
|
||||||
deprint("[[ Positions ]]", x, y, z);
|
deprint("[[ Positions ]]", x, y, z);
|
||||||
deprint("[[ p, e, q ]]", p, e, q);
|
deprint("[[ p, e, q ]]", p, e, q);
|
||||||
}
|
}
|
||||||
if showProgress then
|
if showProgress then
|
||||||
writeln("time = ", format("%e", time), ", dt=", format("%e", deltatime),
|
writef("time = %er, dt=%er, %s", time, deltatime,
|
||||||
if doTiming then ", elapsed = " + (getCurrentTime()-iterTime)
|
if doTiming then ", elapsed = " + (getCurrentTime()-iterTime) +"\n"
|
||||||
else "");
|
else "\n");
|
||||||
}
|
}
|
||||||
if (cycle == maxcycles) {
|
if (cycle == maxcycles) {
|
||||||
writeln("Stopped early due to reaching maxnumsteps");
|
writeln("Stopped early due to reaching maxnumsteps");
|
||||||
@@ -314,12 +314,10 @@ proc main() {
|
|||||||
if printCoords {
|
if printCoords {
|
||||||
var outfile = open("coords.out", iomode.cw);
|
var outfile = open("coords.out", iomode.cw);
|
||||||
var writer = outfile.writer();
|
var writer = outfile.writer();
|
||||||
var fmtstr = if debug then "%1.9e" else "%1.4e";
|
var fmtstr = if debug then "%1.9re %1.9er %1.9er\n"
|
||||||
for i in Nodes {
|
else "%1.4er %1.4er %1.4er\n";
|
||||||
writer.writeln(format(fmtstr, x[i]), " ",
|
for i in Nodes do
|
||||||
format(fmtstr, y[i]), " ",
|
writer.writef(fmtstr, x[i], y[i], z[i]);
|
||||||
format(fmtstr, z[i]));
|
|
||||||
}
|
|
||||||
writer.close();
|
writer.close();
|
||||||
outfile.close();
|
outfile.close();
|
||||||
}
|
}
|
||||||
@@ -479,7 +477,7 @@ inline proc localizeNeighborNodes(eli: index(Elems),
|
|||||||
y: [] real, ref y_local: 8*real,
|
y: [] real, ref y_local: 8*real,
|
||||||
z: [] real, ref z_local: 8*real) {
|
z: [] real, ref z_local: 8*real) {
|
||||||
|
|
||||||
for param i in 1..nodesPerElem {
|
for i in 1..nodesPerElem {
|
||||||
const noi = elemToNode[eli][i];
|
const noi = elemToNode[eli][i];
|
||||||
|
|
||||||
x_local[i] = x[noi];
|
x_local[i] = x[noi];
|
||||||
@@ -670,7 +668,7 @@ proc SumElemStressesToNodeForces(b_x: 8*real, b_y: 8*real, b_z: 8*real,
|
|||||||
ref fx: 8*real,
|
ref fx: 8*real,
|
||||||
ref fy: 8*real,
|
ref fy: 8*real,
|
||||||
ref fz: 8*real) {
|
ref fz: 8*real) {
|
||||||
for param i in 1..8 {
|
for i in 1..8 {
|
||||||
fx[i] = -(stress_xx * b_x[i]);
|
fx[i] = -(stress_xx * b_x[i]);
|
||||||
fy[i] = -(stress_yy * b_y[i]);
|
fy[i] = -(stress_yy * b_y[i]);
|
||||||
fz[i] = -(stress_zz * b_z[i]);
|
fz[i] = -(stress_zz * b_z[i]);
|
||||||
@@ -725,17 +723,17 @@ inline proc CalcElemFBHourglassForce(xd: 8*real, yd: 8*real, zd: 8*real,
|
|||||||
var hx, hy, hz: 4*real;
|
var hx, hy, hz: 4*real;
|
||||||
|
|
||||||
// reduction
|
// reduction
|
||||||
for param i in 1..4 {
|
for i in 1..4 {
|
||||||
for param j in 1..8 {
|
for j in 1..8 {
|
||||||
hx[i] += hourgam[j][i] * xd[j];
|
hx[i] += hourgam[j][i] * xd[j];
|
||||||
hy[i] += hourgam[j][i] * yd[j];
|
hy[i] += hourgam[j][i] * yd[j];
|
||||||
hz[i] += hourgam[j][i] * zd[j];
|
hz[i] += hourgam[j][i] * zd[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for param i in 1..8 {
|
for i in 1..8 {
|
||||||
var shx, shy, shz: real;
|
var shx, shy, shz: real;
|
||||||
for param j in 1..4 {
|
for j in 1..4 {
|
||||||
shx += hourgam[i][j] * hx[j];
|
shx += hourgam[i][j] * hx[j];
|
||||||
shy += hourgam[i][j] * hy[j];
|
shy += hourgam[i][j] * hy[j];
|
||||||
shz += hourgam[i][j] * hz[j];
|
shz += hourgam[i][j] * hz[j];
|
||||||
@@ -1088,16 +1086,16 @@ proc CalcFBHourglassForceForElems(determ, x8n, y8n, z8n, dvdx, dvdy, dvdz) {
|
|||||||
|
|
||||||
/* TODO: Can we enable this local block? */
|
/* TODO: Can we enable this local block? */
|
||||||
// local {
|
// local {
|
||||||
for param i in 1..4 {
|
for i in 1..4 {
|
||||||
var hourmodx, hourmody, hourmodz: real;
|
var hourmodx, hourmody, hourmodz: real;
|
||||||
// reduction
|
// reduction
|
||||||
for param j in 1..8 {
|
for j in 1..8 {
|
||||||
hourmodx += x8n[eli][j] * gammaCoef[i][j];
|
hourmodx += x8n[eli][j] * gammaCoef[i][j];
|
||||||
hourmody += y8n[eli][j] * gammaCoef[i][j];
|
hourmody += y8n[eli][j] * gammaCoef[i][j];
|
||||||
hourmodz += z8n[eli][j] * gammaCoef[i][j];
|
hourmodz += z8n[eli][j] * gammaCoef[i][j];
|
||||||
}
|
}
|
||||||
|
|
||||||
for param j in 1..8 {
|
for j in 1..8 {
|
||||||
hourgam[j][i] = gammaCoef[i][j] - volinv *
|
hourgam[j][i] = gammaCoef[i][j] - volinv *
|
||||||
(dvdx[eli][j] * hourmodx +
|
(dvdx[eli][j] * hourmodx +
|
||||||
dvdy[eli][j] * hourmody +
|
dvdy[eli][j] * hourmody +
|
||||||
@@ -1221,7 +1219,7 @@ proc CalcKinematicsForElems(dxx, dyy, dzz, const dt: real) {
|
|||||||
arealg[k] = CalcElemCharacteristicLength(x_local, y_local, z_local,
|
arealg[k] = CalcElemCharacteristicLength(x_local, y_local, z_local,
|
||||||
volume);
|
volume);
|
||||||
|
|
||||||
for param i in 1..8 {
|
for i in 1..8 {
|
||||||
x_local[i] -= dt2 * xd_local[i];
|
x_local[i] -= dt2 * xd_local[i];
|
||||||
y_local[i] -= dt2 * yd_local[i];
|
y_local[i] -= dt2 * yd_local[i];
|
||||||
z_local[i] -= dt2 * zd_local[i];
|
z_local[i] -= dt2 * zd_local[i];
|
||||||
@@ -1669,7 +1667,7 @@ proc CalcSoundSpeedForElems(vnewc, rho0:real, enewc, pnewc, pbvc, bvc) {
|
|||||||
|
|
||||||
|
|
||||||
iter elemToNodes(elem) {
|
iter elemToNodes(elem) {
|
||||||
for param i in 1..nodesPerElem do
|
for i in 1..nodesPerElem do
|
||||||
yield elemToNode[elem][i];
|
yield elemToNode[elem][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1679,14 +1677,19 @@ iter elemToNodesTuple(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
proc deprint(title:string, x:[?D] real, y:[D]real, z:[D]real) {
|
proc deprint(title:string, x:[?D] real, y:[D] real, z:[D] real) {
|
||||||
writeln(title);
|
writeln(title);
|
||||||
for i in D {
|
for i in D do
|
||||||
writeln(format("%3d", i), ": ",
|
writef("%3i: %3.4er %3.4er %3.4er\n",
|
||||||
format("%3.4e", x[i]), " ",
|
if use3DRepresentation then idx3DTo1D(i, D.dim(1).size) else i,
|
||||||
format("%3.4e", y[i]), " ",
|
x[i], y[i], z[i]);
|
||||||
format("%3.4e", z[i]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
proc deprintatomic(title:string, x:[?D] atomic real, y:[] atomic real, z:[] atomic real) {
|
||||||
|
writeln(title);
|
||||||
|
for i in D do
|
||||||
|
writef("%3i: %3.4er %3.4er %3.4er\n",
|
||||||
|
if use3DRepresentation then idx3DTo1D(i, D.dim(1).size) else i,
|
||||||
|
x[i].peek(), y[i].peek(), z[i].peek());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user