Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
X10 X10.lang.FailedDynamicCheckException:!(这里==x$0.home)C++;后端_Exception_X10 Language - Fatal编程技术网

X10 X10.lang.FailedDynamicCheckException:!(这里==x$0.home)C++;后端

X10 X10.lang.FailedDynamicCheckException:!(这里==x$0.home)C++;后端,exception,x10-language,Exception,X10 Language,我目前正在使用X10,并且有多个异常。这是我创建的代码: Main.x10 public class Main { // main Method for the Main class public static def main(argv:Rail[String]) { Console.OUT.println("This is the main place. (ID="+here.id+")"); val dataItem = new Data(); // no glo

我目前正在使用X10,并且有多个异常。这是我创建的代码:

Main.x10

public class Main {

// main Method for the Main class
public static def main(argv:Rail[String]) {
    Console.OUT.println("This is the main place. (ID="+here.id+")");
    val dataItem = new Data();
    // no global reference, data is copied to each place.
    finish for (p in Place.places()) {
        at (p) async {
            Console.OUT.println("This is place no: "+here.id+". The value of dataItem is "+dataItem.getValue()+".");
            dataItem.incValue();
        }
    }
    Console.OUT.println("Final value of dataItem without GlobalRef in multiple places at place "+here.id+": "+dataItem.getValue());
    dataItem.setValue(0);
    finish for (p in Place.places()) {
        async {
            Console.OUT.println("This is place no: "+here.id+". The value of dataItem is "+dataItem.getValue()+".");
            dataItem.incValue();
        }
    }
    Console.OUT.println("Final value of dataItem without GlobalRef in one place at place "+here.id+": "+dataItem.getValue());
    dataItem.setValue(0);
    val globalRefDataItem = GlobalRef[Data](dataItem);
    finish for (p in Place.places()) {
        at (p) async {
            val globalDataItemUnwrapped = globalRefDataItem();
            Console.OUT.println("This is place no: "+here.id+". The value of dataItem is "+globalDataItemUnwrapped.getValue()+".");
            atomic globalDataItemUnwrapped.incValue();
        }
    }
    Console.OUT.println("Final value of dataItem with GlobalRef in multiple places at place "+here.id+": "+dataItem.getValue());
}
}

Data.x10

public class Data{
private var value:Long;
def getValue():Long{
    return value;
}
def setValue(value:long){
    this.value = value;
}
def incValue(){
    this.value = this.value+1;
}
}
X10DT的输出如下所示:

This is the main place. (ID=0)
This is place no: 3. The value of dataItem is 0.
This is place no: 1. The value of dataItem is 0.
This is place no: 2. The value of dataItem is 0.
This is place no: 0. The value of dataItem is 0.
Final value of dataItem without GlobalRef in multiple places at place 0: 0
This is place no: 0. The value of dataItem is 0.
This is place no: 0. The value of dataItem is 1.
This is place no: 0. The value of dataItem is 2.
This is place no: 0. The value of dataItem is 3.
Final value of dataItem without GlobalRef in one place at place 0: 4
This is place no: 0. The value of dataItem is 0.
Command used: /home/martze/x10dt/workspace/Example/bin/Main
Uncaught exception at place 0: x10.lang.MultipleExceptions
x10.lang.FailedDynamicCheckException: !(here == x$0.home)
at x10aux::throwException(x10::lang::CheckedThrowable*)
at Main__closure__3::__apply()
at x10::lang::Activity::run()
at x10::lang::Runtime__Worker::loop()
at x10::lang::Runtime__Worker::__apply()
at x10::lang::Runtime__Pool::run()
at 
at GC_inner_start_routine
at GC_call_with_stack_base
at 
at clone
x10.lang.FailedDynamicCheckException: !(here == x$0.home)
at x10aux::throwException(x10::lang::CheckedThrowable*)
at Main__closure__3::__apply()
at x10::lang::Activity::run()
at x10::lang::Runtime__Worker::loop()
at x10::lang::Runtime__Worker::__apply()
at x10::lang::Runtime__Pool::run()
at 
at GC_inner_start_routine
at GC_call_with_stack_base
at 
at clone
x10.lang.FailedDynamicCheckException: !(here == x$0.home)
at x10aux::throwException(x10::lang::CheckedThrowable*)
at Main__closure__3::__apply()
at x10::lang::Activity::run()
at x10::lang::Runtime__Worker::loop()
at x10::lang::Runtime__Worker::__apply()
at x10::lang::Runtime__Pool::run()
at 
at GC_inner_start_routine
at GC_call_with_stack_base
at 
at clone
我试着用谷歌搜索,但结果只是指向一些对我毫无帮助的文档。我的环境变量设置为X10\u NTHREADS=1,我将位置数设置为4。我正在使用Ubuntu,我使用C++后端。< /P>
如何处理此错误以及此错误的含义是什么?

A
GlobalRef
是对特定位置的对象的具有全局意义的引用。它只能在创建它的位置(“主”位置)取消引用。在
GlobalRef
的解引用(“展开”)时引发异常:

val globalRefDataItem = GlobalRef[Data](dataItem);
finish for (p in Place.places()) {
  at (p) async {
    val globalDataItemUnwrapped = globalRefDataItem();
    ...
  }
}
GlobalRef
是在位置0处创建的,但正在位置
p
处取消引用(
globalRefDataItem()
)。如果该错误为:

x10.lang.FailedDynamicCheckException: (here != globalRefDataItem.home)
要访问由
GlobalRef
引用的对象,活动必须将地点更改回起始地点。例如:

val globalRefDataItem = GlobalRef[Data](dataItem);
finish for (p in Place.places()) {
  at (p) async {
    at(globalRefDataItem.home) {
      atomic globalDataItemUnwrapped.incValue();
    }
  }
}
finish for (p in Place.places()) {
  at (p) async {
    val currentValue = at(globalRefDataItem.home) {
      val globalDataItemUnwrapped = globalRefDataItem();
      var valueBeforeInc:Long = 0;
      atomic {
        valueBeforeInc = globalDataItemUnwrapped.getValue();
        globalDataItemUnwrapped.incValue();
      }
      valueBeforeInc
    };
    Console.OUT.println("This is place no: "+here.id+". The value of dataItem is "+currentValue+".");
  }
}
这通常被称为“乒乓球”习语——活动变为一个遥远的地方,然后又变回原来的地方

在您的程序中,增加了一项要求,即在增加数据项之前打印数据项的值。为此,使用at表达式(§13.3)从远程位置返回值,例如:

val globalRefDataItem = GlobalRef[Data](dataItem);
finish for (p in Place.places()) {
  at (p) async {
    at(globalRefDataItem.home) {
      atomic globalDataItemUnwrapped.incValue();
    }
  }
}
finish for (p in Place.places()) {
  at (p) async {
    val currentValue = at(globalRefDataItem.home) {
      val globalDataItemUnwrapped = globalRefDataItem();
      var valueBeforeInc:Long = 0;
      atomic {
        valueBeforeInc = globalDataItemUnwrapped.getValue();
        globalDataItemUnwrapped.incValue();
      }
      valueBeforeInc
    };
    Console.OUT.println("This is place no: "+here.id+". The value of dataItem is "+currentValue+".");
  }
}

注意,我对原始代码做了一个重要的更改,将get和值的增量合并到一个
原子块中。如果没有此更改,另一个活动可能会增加这两条语句之间的值。X10提供了原子类型(例如
X10.util.concurrent.AtomicLong
),它提供了这样一个原子
getAndIncrement
操作。

好的。这是有道理的。但是,有没有一种方法可以在远程位置执行活动,同时访问另一个位置的数据?用乒乓球的习惯用语来说,这不是把数据复制到一个遥远的地方和后面,然后工作吗?听起来很奇怪。一般来说,活动只能访问驻留在当前位置的数据。当一个
GlobalRef
被发送到一个远程位置时,实际发送的只是一个在本地有意义的标识符(如指针);未复制实际目标对象。因此,在乒乓球中,标识符被发送到位置
p
,然后返回到起始位置。