Hi Chapel Developers --

A user noticed that we don't replicate global constants across locales as we do for integers and other scalar types (and advertise in the spec), which seemed like, and was, a five-minute fix (TM). While here, I noticed other scalar types that weren't being replicated (imaginaries, complexes, bools of non-default width I think?), so added them in as well and created a test to lock the behavior in for default-sized scalar types.

This has passed full single-locale testing and the multilocale/ and examples/ gasnet directories.

Patch attached.  Proposed commit message below.

-Brad

-----


Extend replication of global constants to other types

This commit fixes a bug/oversight in which we failed to replicate global constants of simple types across locales as advertised in the spec. It adds enums, imaginaries, and complexes to the list of things to be replicated. It also changes the test used for booleans from a simple comparison to dtBool (which I think would only cover default-width boolean types?) to use is_bool_type(), more symmetrically with other types.

One case that I was curious about but did not investigate (due to lack of time, difficulty in verifying, and perhaps good motivating examples) was whether global const class variables are replicated (which would correspond to replicating the reference to the object, not the object itself). So that remains an open question for future investigation.

Added a test to lock this behavior in.
Index: test/multilocale/bradc/globalConstRepl.chpl
===================================================================
--- test/multilocale/bradc/globalConstRepl.chpl	(revision 0)
+++ test/multilocale/bradc/globalConstRepl.chpl	(revision 0)
@@ -0,0 +1,27 @@
+enum color {red, blue};
+
+record R {
+  var i: int;
+}
+
+const b: bool = true;
+const n: int = 1;
+const u: uint = 2;
+const r: real = 3.4;
+const i: imag = 5.6i;
+const c: complex = 7.8 + 9.0i;
+const e: color = color.red;
+const s: string = "hi";
+const myR: R = new R(i=11);
+
+on Locales[(here.id + 1) % numLocales] {
+  writeln("b is ", b, " and is on locale: ", b.locale.id);
+  writeln("n is ", n, " and is on locale: ", n.locale.id);
+  writeln("u is ", u, " and is on locale: ", u.locale.id);
+  writeln("r is ", r, " and is on locale: ", r.locale.id);
+  writeln("i is ", i, " and is on locale: ", i.locale.id);
+  writeln("c is ", c, " and is on locale: ", c.locale.id);
+  writeln("e is ", e, " and is on locale: ", e.locale.id);
+  writeln("s is ", s, " and is on locale: ", s.locale.id);
+  writeln("myR is ", myR, " and is on locale: ", myR.locale.id);
+}
Index: test/multilocale/bradc/globalConstRepl.good
===================================================================
--- test/multilocale/bradc/globalConstRepl.good	(revision 0)
+++ test/multilocale/bradc/globalConstRepl.good	(revision 0)
@@ -0,0 +1,9 @@
+b is true and is on locale: 1
+n is 1 and is on locale: 1
+u is 2 and is on locale: 1
+r is 3.4 and is on locale: 1
+i is 5.6i and is on locale: 1
+c is 7.8 + 9.0i and is on locale: 1
+e is red and is on locale: 1
+s is hi and is on locale: 1
+myR is (i = 11) and is on locale: 1
Index: test/multilocale/bradc/globalConstRepl.comm-none.good
===================================================================
--- test/multilocale/bradc/globalConstRepl.comm-none.good	(revision 0)
+++ test/multilocale/bradc/globalConstRepl.comm-none.good	(revision 0)
@@ -0,0 +1,9 @@
+b is true and is on locale: 0
+n is 1 and is on locale: 0
+u is 2 and is on locale: 0
+r is 3.4 and is on locale: 0
+i is 5.6i and is on locale: 0
+c is 7.8 + 9.0i and is on locale: 0
+e is red and is on locale: 0
+s is hi and is on locale: 0
+myR is (i = 11) and is on locale: 0
Index: compiler/passes/parallel.cpp
===================================================================
--- compiler/passes/parallel.cpp	(revision 22425)
+++ compiler/passes/parallel.cpp	(working copy)
@@ -678,10 +678,13 @@
                !def->sym->hasFlag(FLAG_PRIVATE) &&
                !def->sym->hasFlag(FLAG_EXTERN)) {
       if (def->sym->hasFlag(FLAG_CONST) &&
-          (is_int_type(def->sym->type) ||
+          (is_bool_type(def->sym->type) ||
+           is_enum_type(def->sym->type) ||
+           is_int_type(def->sym->type) ||
            is_uint_type(def->sym->type) ||
            is_real_type(def->sym->type) ||
-           def->sym->type == dtBool ||
+           is_imag_type(def->sym->type) ||
+           is_complex_type(def->sym->type) ||
            (isRecord(def->sym->type) &&
             !isRecordWrappedType(def->sym->type) &&
             // sync/single are currently classes, so this shouldn't matter
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers

Reply via email to