Skip to content
Snippets Groups Projects
Commit 8c04bd53 authored by Adam Welc's avatar Adam Welc
Browse files

Added a spawn function that does not block waiting for the result of parallel computation.

parent b04cb64b
Branches
No related tags found
No related merge requests found
......@@ -64,6 +64,21 @@ public class FastRContext {
}
}
public abstract static class Spawn extends RExternalBuiltinNode.Arg2 {
@Specialization
protected RNull eval(RIntVector contexts, RAbstractStringVector exprs) {
RContext.EvalThread[] threads = new RContext.EvalThread[contexts.getLength()];
for (int i = 0; i < threads.length; i++) {
RContext context = checkContext(contexts.getDataAt(i));
threads[i] = new RContext.EvalThread(context, Source.fromText(exprs.getDataAt(i % threads.length), "<context_eval>"));
}
for (int i = 0; i < threads.length; i++) {
threads[i].start();
}
return RNull.instance;
}
}
public abstract static class Eval extends RExternalBuiltinNode.Arg3 {
@Specialization
protected RNull eval(RIntVector contexts, RAbstractStringVector exprs, byte par) {
......
......@@ -13,6 +13,7 @@ export(fastr.inspect)
export(fastr.createpkgsources)
export(fastr.createpkgsource)
export(fastr.context.create)
export(fastr.context.spawn)
export(fastr.context.eval)
export(fastr.context.pareval)
export(print.fastr_context)
......@@ -87,6 +87,11 @@ print.fastr_context <- function(x, ...) {
invisible(x)
}
fastr.context.spawn <- function(contexts, exprs) {
.FastR(.NAME="context.spawn", contexts, exprs)
invisible(NULL)
}
fastr.context.eval <- function(contexts, exprs, par=FALSE) {
.FastR(.NAME="context.eval", contexts, exprs, par)
invisible(NULL)
......
......@@ -88,6 +88,8 @@ public abstract class FastR extends RBuiltinNode {
return FastRContextFactory.CreateNodeGen.create();
case "context.print":
return FastRContextFactory.PrintNodeGen.create();
case "context.spawn":
return FastRContextFactory.SpawnNodeGen.create();
case "context.eval":
return FastRContextFactory.EvalNodeGen.create();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment