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.
Deze oefening maakt deel uit van de cursus
Parallel Programming in R
Oefeninstructies
- Generate a cluster of four cores.
- Export
test_varandtest_sumto the cluster. - Print "Accuracy OK" if the sum of
test_varequalstest_sum, else print "Errors". - Stop the cluster.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# 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
___