Get startedGet started for free

Running code on the cluster

You work for a data consultancy and your company uses a lot of parallel R code. But lately, the results have been erratic, and sometimes the code gives varying results for the same input. Before any further troubleshooting, you have decided to run a basic check on each cluster.

You have created a variable test_var and calculated the sum of all its elements, test_sum. You want to check if each cluster can sum this variable accurately. The parallel package has been loaded for you.

This exercise is part of the course

Parallel Programming in R

View Course

Exercise instructions

  • Generate a cluster of four cores.
  • Export test_var and test_sum to the cluster.
  • Print "Accuracy OK" if the sum of test_var equals test_sum, else print "Errors".
  • Stop the cluster.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Make a cluster of four cores
cl <- ___
# Export test_var and test_sum to cluster
clusterExport(___, ___, envir = environment())
# Check the sum on cluster
clusterEvalQ(___, {
  ___
  
  
})
# Stop cluster
___
Edit and Run Code