I've a code that works perfectly for my purpose (it reads some files with a specific pattern, read the matrix within each file and compute something using each filepair...the final output is a matrix that has the same size of the file number) and looks like this:
m<- 100 output<- matrix(0, m, m) lista<- list.files(pattern = "q") listan<- as.matrix(lista) n <- nrow(listan) for (i in 1:n) { AA <- read.table((listan[i,]), header = FALSE) A<- as.matrix(AA) dVarX <- sqrt(mean(A * A)) for (j in i:n) { BB <- read.table ((listan[j,]), header = FALSE) B<- as.matrix(BB) V <- sqrt (dVarX * (sqrt(mean(B * B)))) output[i,j] <- (sqrt(mean(A * B))) / V } } My problem is that it takes a lot of time (I have about 5000 matrixes, that means 5000x5000 loops). I would like to parallelize, but I need some help! Waiting for your kind suggestions!
Thank you in advance!
Gab
?read.tableexplicitly says, "Usescaninstead for matrices."sqrt(mean(B*B))for each matrix. Parallelizing code this inefficient is like trying to speed up your commute to work by running from your house to your car instead of walking.