Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 4 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: http://www.rforge.net/multicore 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
1  
@Produnis You can easily turn your loops into parallel ones like this: result <- mclapply(as.data.frame(t(x)), max). This example would find by-row maximums using all your CPUs. –  ulidtko Jan 19 '11 at 18:02
add comment

Your Answer

 
discard

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.