Próbuję uruchomić kod R i awarie z powodu pamięci. Błąd, który pojawia się:Długie wektory mclapply nie są jeszcze obsługiwane
Error in sendMaster(try(lapply(X = S, FUN = FUN, ...), silent = TRUE)) :
long vectors not supported yet: memory.c:3100
Funkcja, która stwarza problemy to:
StationUserX <- function(userNDX){
lat1 = deg2rad(geolocation$latitude[userNDX])
long1 = deg2rad(geolocation$longitude[userNDX])
session_user_id = as.character(geolocation$session_user_id[userNDX])
#Find closest station
Distance2Stations <- unlist(lapply(stationNDXs, Distance2StationX, lat1, long1))
# Return index for closest station and distance to closest station
stations_userX = data.frame(session_user_id = session_user_id,
station = ghcndstations$ID[stationNDXs],
Distance2Station = Distance2Stations)
stations_userX = stations_userX[with(stations_userX, order(Distance2Station)), ]
stations_userX = stations_userX[1:100,] #only the 100 closest stations...
row.names(stations_userX)<-NULL
return(stations_userX)
}
uruchomić tę funkcję za pomocą mclapply 50k razy. StationUserX dzwoni do Distance2StationX 90k razy.
Czy istnieje oczywisty sposób optymalizacji funkcji StationUserX?
Czy masz "Vectorize" lub 'cmpfun' '' '' '' '' '' '' '' '' –
również myśleć o "foreach" dla równoległości, co jest trywialne w implementacji –