首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将多核与Snow集群相结合

将多核与Snow集群相结合
EN

Stack Overflow用户
提问于 2012-07-24 13:05:59
回答 1查看 1.1K关注 0票数 2

对Parallel R相当陌生。快速问题。我有一个计算密集型的算法。幸运的是,为了利用multicoresnow,可以很容易地将其分解为多个部分。我想知道的是,结合使用multicoresnow在实践中是否被认为是可以接受的

我想要做的是将我的负载分开,以便在集群中的多台机器上运行,并且为每台机器运行。我想要利用机器上的所有内核。对于这种类型的处理,将雪与multicore混合是否合理

EN

回答 1

Stack Overflow用户

发布于 2012-11-30 18:15:25

我使用了上面lockedoff建议的方法,即使用并行包在具有多个内核的多台机器上分配令人尴尬的并行工作负载。首先,工作负载分布在所有机器上,然后每台机器的工作负载分布在它的所有核心上。这种方法的缺点是机器之间没有负载平衡(至少我不知道是如何实现的)。

所有加载的r代码应该是相同的,并且在所有机器上的相同位置(svn)。因为初始化集群需要相当长的时间,所以可以通过重用创建的集群来改进下面的代码。

代码语言:javascript
复制
foo <- function(workload, otherArgumentsForFoo) {
    source("/home/user/workspace/mycode.R")
    ...
}

distributedFooOnCores <- function(workload) {
    # Somehow assign a batch number to every record
    workload$ParBatchNumber = NA
    # Split the assigned workload into batches according to DistrParNumber
    batches = by(workload, workload$ParBatchNumber, function(x) x)

    # Create a cluster with workers on all machines 
    library("parallel")
    cluster = makeCluster(detectCores(), outfile="distributedFooOnCores.log")
    batches = parLapply(cluster, batches, foo, otherArgumentsForFoo)
    stopCluster(cluster)

    # Merge the resulting batches
    results = someEmptyDataframe
    p = 1;
    for(i in 1:length(batches)){
        results[p:(p + nrow(batches[[i]]) - 1), ] = batches[[i]]
        p = p + nrow(batches[[i]])      
    }

    # Clean up
    workload$ParBatchNumber = NULL
    return(invisible(results))
}

distributedFooOnMachines <- function(workload) {
    # Somehow assign a batch number to every record
    workload$DistrBatchNumber = NA
    # Split the assigned activity into batches according to DistrBatchNumber
    batches = by(workload, workload$DistrBatchNumber, function(x) x)

    # Create a cluster with workers on all machines 
    library("parallel")
    # If makeCluster hangs, please make sure passwordless ssh is configured on all machines
    cluster = makeCluster(c("machine1", "etc"), master="ub2", user="", outfile="distributedFooOnMachines.log")
    batches = parLapply(cluster, batches, foo, otherArgumentsForFoo)
    stopCluster(cluster)

    # Merge the resulting batches
    results = someEmptyDataframe
    p = 1;
    for(i in 1:length(batches)){
        results[p:(p + nrow(batches[[i]]) - 1), ] = batches[[i]]
        p = p + nrow(batches[[i]])      
    }

    # Clean up
    workload$DistrBatchNumber = NULL
    return(invisible(results))
}

我感兴趣的是如何改进上面的方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11624460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档