Parallelized optimization in R

后端 未结 4 1562
梦谈多话
梦谈多话 2021-02-12 12:24

I\'m running R on linux box that has 8 multicore processors, and have an optimization problem I\'d like to speed up by parallelizing the optimization routine itself. Importantly

4条回答
  •  深忆病人
    2021-02-12 13:03

    I used the package doSNOW to run a code on 8 cores. I can just copy&paste the part of the code that refers to this package. Hope it helps!

        # use multicore libraries
          # specify number of cores to use
        cores<- 8
          cluster <- makeCluster(cores, type="SOCK")
          registerDoSNOW(cluster)
    
          # check how many cores will be used
          ncores <- getDoParWorkers()
        print(paste("Computing algorithm for ", cores, " cores", sep=""))
          fph <- rep(-100,12)
    
          # start multicore cicle on 12  subsets
          fph <- foreach(i=1:12, .combine='c') %dopar% {
            PhenoRiceRun(sub=i, mpath=MODIS_LOCAL_DIR, masklocaldir=MASK_LOCAL_DIR, startYear=startYear, tile=tile, evismoothopt=FALSE)
          }
    
    
      stopCluster(cluster) # check if gives error
      gc(verbose=FALSE)
    

提交回复
热议问题