# rnorm(z,a,b) produce z valores aleatorios normales(a,b) ######## Secuencial ####### # Parámetros para la normal a = 2 b = 7 t1 = Sys.time() # tiempo inicial del sitema y1 = rnorm(55000000,a,b) t11 = Sys.time() # tiempo final del sitema para la primera norma y2 = rnorm(60000000,a,b) t12 = Sys.time() # tiempo final del sistema para la segunda norma t2 = Sys.time() # tiempo final del sistema tt = t2-t1 res_secuencial = c(secuencial=tt,parte_1=t11-t1,parte_2=t12-t11) res_secuencial ########## Paralelo ########## # El mismo código en paralelo con 2 nodos no.estandares = function(x,a,b){ m1 = 0 m2 = 0 if(x==1) { m1 = Sys.time() y = rnorm(55000000,a,b) m2 = Sys.time() } if(x==2) { m1 = Sys.time() y = rnorm(60000000,a,b) m2 = Sys.time() } d = as.numeric(difftime(m2,m1), units="secs") # Calcula m1-m2 z = list() z[[1]] = y z[[2]] = m1 z[[3]] = m2 z[[4]] = d return(z) } library(parallel) cl <- makeCluster(2) l1 = Sys.time() res = clusterApply(cl, x = 1:2, fun = no.estandares,2,7) l2 = Sys.time() stopCluster(cl) res_paralelo = c(secuencial=tt,paralelo_total = difftime(l2,l1), paralelo_1 = res[[1]][[4]], paralelo_2= res[[2]][[4]] ) res_secuencial res_paralelo