【问题标题】:Constructing a Sparse Tropical Limit Function in Chapel在 Chapel 中构建稀疏热带极限函数
【发布时间】:2018-03-21 22:39:29
【问题描述】:

给定矩阵AB,热带乘积被定义为通常的矩阵乘积,乘法换成加法,加法换成minimum。也就是说,它返回一个新矩阵C,这样,

C_ij = minimum(A_ij, B_ij, A_i1 + B_1j, A_i2 + B_12,..., A_im + B_mj)

给定图g 的底层邻接矩阵A_g,关于热带积的nth“幂”表示最多在n 步骤中可达的节点之间的连接。也就是说,如果节点ijm<=n 边分隔,则C_ij = (A**n)_ij 的值是m

一般来说,给定一些带有N 节点的图。图的直径最多只能是N;并且,给定一个直径为kA**n = A**k 的图,所有n>k 和矩阵D_ij = A**k 称为“距离矩阵”条目,表示图中所有节点之间的距离。

我在教堂里写了一个热带积函数,我想写一个函数,它接受一个邻接矩阵并返回结果距离矩阵。我尝试了以下方法无济于事。非常感谢您提供克服这些错误的指导!

proc tropicLimit(A:[] real,B:[] real) {
 var R = tropic(A,B);
 if A == R {
   return A;
 } else {
   tropicLimit(R,B);
 }
}

这引发了域不匹配错误,因此我进行了以下编辑:

proc tropicLimit(A:[] real,B:[] real) {
 var R = tropic(A,B);
 if A.domain == R.domain {
   if && reduce (A == R) {
     return R;
   } else {
     tropicLimit(R,B);
   }
 } else {
   tropicLimit(R,B);
 }
}

抛出

src/MatrixOps.chpl:602: error: control reaches end of function that returns a value

proc tropicLimit(A:[] real,B:[] real) {
 var R = tropic(A,B);
 if A.domain == R.domain {
   if && reduce (A == R) {  // Line 605 is this one
   } else {
     tropicLimit(R,B);
   }
 } else {
   tropicLimit(R,B);
 }
return R;
}

让我回到这个错误

src/MatrixOps.chpl:605: error: halt reached - Sparse arrays can't be zippered with anything other than their domains and sibling arrays (CS layout)

我也尝试使用带有break 条件的for 循环,但这也不起作用

proc tropicLimit(B:[] real) {
 var R = tropic(B,B);
 for n in B.domain.dim(2) {
   var S = tropic(R,B);
   if S.domain != R.domain {
    R = S; // Intended to just reassign the handle "R" to the contents of "S" i.o.w. destructive update of R
   } else {
     break;
   }   
 }
 return R;
}

有什么建议吗?

【问题讨论】:

    标签: graph sparse-matrix hpc convergence chapel


    【解决方案1】:

    src/MatrixOps.chpl:605: 错误:已停止 - 稀疏数组不能与域和兄弟数组(CS 布局)以外的任何东西一起压缩

    我相信您在当前实现中遇到了压缩稀疏数组的限制,记录在 #6577 中。

    从等式中删除一些未知数,我相信这个蒸馏代码 sn-p 说明了您遇到的问题:

    use LayoutCS;
    
    var dom = {1..10, 1..10};
    
    var Adom: sparse subdomain(dom) dmapped CS();
    var Bdom: sparse subdomain(dom) dmapped CS();
    
    var A: [Adom] real;
    var B: [Bdom] real;
    
    Adom += (1,1);
    Bdom += (1,1);
    
    A[1,1] = 1.0;
    B[1,1] = 2.0;
    
    
    writeln(A.domain == B.domain); // true
    var willThisWork = && reduce (A == B);
    // dang.chpl:19: error: halt reached - Sparse arrays can't be zippered with
    //           anything other than their domains and sibling arrays (CS layout)
    

    作为一种解决方法,我建议在确认域相等并执行&& reduce 之后循环遍历稀疏索引。这是您可以包装在辅助函数中的东西,例如

    proc main() { 
      var dom = {1..10, 1..10};
    
      var Adom: sparse subdomain(dom) dmapped CS();
      var Bdom: sparse subdomain(dom) dmapped CS();
    
      var A: [Adom] real;
      var B: [Bdom] real;
    
      Adom += (1,1);
      Bdom += (1,1);
    
      A[1,1] = 1.0;
      B[1,1] = 2.0;
    
      if A.domain == B.domain {
        writeln(equal(A, B));
      }
    }
    
    /* Some day, this should be A.equals(B) ! */
    proc equal(A: [], B: []) {
      // You could also return 'false' if domains do not match
      assert(A.domain == B.domain);
    
      var s = true;
    
      forall (i,j) in A.domain with (&& reduce s) {
        s &&= (A[i,j] == B[i,j]);
      }
    
      return s;
    }
    

    src/MatrixOps.chpl:602: 错误:控制到达返回值的函数的结尾

    此错误是由于没有在每种情况下都返回某些内容。我相信你打算这样做:

    proc tropicLimit(A:[] real,B:[] real) {
     var R = tropic(A,B);
     if A.domain == R.domain {
       if && reduce (A == R) {
         return R;
       } else {
         return tropicLimit(R,B);
       }
     } else {
       return tropicLimit(R,B);
     }
    }
    

    【讨论】:

    • 只有一个问题。我还举了几个我尝试过但没有用的例子。编译器无法使用您建议的这两个编辑解析返回类型
    猜你喜欢
    • 2018-08-22
    • 2018-08-23
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    相关资源
    最近更新 更多