Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using GNU R to calculate a huge dataset. My PC has 4 CPU-cores, and I can see, that R is using only 1 CPU.

Is there a way to tell R to use all 4 CPUs in order to make the calculation complete faster?

share|improve this question
Just to be sure: depending on your code there could be no speedup at all. Having more cores doesn't automatically lead to a performance increase. So, are you sure your code should run faster using more cores? – htorque Jan 19 '11 at 12:15
@htorque - In the case of Gnu-R, the data crunching is effected a great deal by access to multiple CPU cores. After all it's academic data crunching meant to be running on big iron as well as desktops. – Martin Owens -doctormo- Jan 19 '11 at 12:45
the calculation contain lots of "for"-loops containing commands for different datasets... I thought that sharing at least these commands to differnt cpu-cores would increase the speed... nevertheless, it is worth a try (as my current calculation-speed will take 5 days to complete!!) – Produnis Jan 19 '11 at 12:47
up vote 5 down vote accepted

You should use the r-cran-multicore package to enable multiple cpu processing:

sudo apt-get install r-cran-multicore

See details about this functionality here: but as a warning, your 'R' code will probably have to be updated to take advantage of multiple core technology. unless you are already using pre-made code which supports the multicore extensions.

share|improve this answer
thanks martin, my current script looks something like this: for(i in length){max(x[i,])} <-- how do I need to change the script in order to use multicore? ("length" and "x" are very large (length>50,000 , x>1700 values in 50,000 rows) – Produnis Jan 19 '11 at 13:01
According to the documentation (linked above) you have to split the job up into parts which are not dependant on each other. In the case of your code, you should endeavour to split it up 4 ways, each loop dealing with 1/4 of the length. How to code this, I don't know in R. – Martin Owens -doctormo- Jan 19 '11 at 14:06
@Produnis You can easily turn your loops into parallel ones like this: result <- mclapply(, max). This example would find by-row maximums using all your CPUs. – ulidtko Jan 19 '11 at 18:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.