我正在使用“igraph”包和“R.utils”中的“evalWithTimeout”函数。
我正在尝试进行最大 clique 检测,我知道它会变得很糟糕(因为 O(3^n) 是 n 个节点)所以我封装在 timeOut 中,但它被忽略了。
重现问题的最少代码
library(igraph)
library(R.utils)
g<-erdos.renyi.game(1e6,1e7,type="gnm")
o<-evalWithTimeout(maximal.cliques(g),timeout=1)
这应该会在一秒钟后停止。然而事实并非如此。我想知道这是否是由于使用了底层 C/Fortran 代码(这是 maximal.cliques 所做的)。如果是这样,我该如何解决?
最佳答案
这不适用于大多数 C 代码,因为 R 不能中断 C 代码,除非 C 代码合作。 evalWithTimeout
调用 setTimeLimit
,这是来自 setTimeLimit
的手册页:
Time limits are checked whenever a user interrupt could occur. This will happen frequently in R code and during
Sys.sleep
, but only at points in compiled C and Fortran code identified by the code author.
使 C 代码可中断并非易事,因为您需要释放所有已分配的内存。
我建议在 https://github.com/igraph/igraph/issues 报告错误并请求使 maximal.cliques
可中断。
关于c - 调用 C/Fortran 例程时忽略 evalWithTimeout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21334820/