Statistiques
| Branche: | Révision :

root / src / man / run_engine.Rd @ b412345d

Historique | Voir | Annoter | Télécharger (2,62 ko)

1 b412345d Florent Chuffart
\name{run_engine}
2 b412345d Florent Chuffart
\alias{run_engine}
3 b412345d Florent Chuffart
\title{# Execute bag of tasks parallely, on as many cores as the current computing node owns.}
4 b412345d Florent Chuffart
\description{This bag of tasks engine forks processes on as many cores as the current computing node owns. Each sub-process takes a task randomly in the list of tasks. For each task, it starts by taking a lock on this task (creating a file named out_filename.lock). Next, it executes the task_processor (a function) using the corresponding set of parameters (task). When this execution is completed, it dumps task_processor results into a results file (named out_filename.RData).}
5 b412345d Florent Chuffart
\usage{run_engine(tasks, task_processor, debug = FALSE, starter_name = "~/.start_best_effort_jobs", 
6 b412345d Florent Chuffart
    rm_starter = TRUE, log_dir = "log", bot_cache_dir = "cache", 
7 b412345d Florent Chuffart
    nb_proc = NULL, ...)}
8 b412345d Florent Chuffart
\arguments{
9 b412345d Florent Chuffart
  \item{tasks}{A list of tasks, each task is a list of key values that will be passed as arguments to the task_processor. Note that task$out_filename is a mandatory parameter.}
10 b412345d Florent Chuffart
  \item{task_processor}{A function that will be called for each task in the task list \emph{tasks}.}
11 b412345d Florent Chuffart
  \item{debug}{If \emph{TRUE} no process will be forked, the list of tasks will be executed in the current process.}
12 b412345d Florent Chuffart
  \item{starter_name}{Path to file that will be deleted after the execution of all tasks if \emph{rm_starter} is set to \emph{TRUE}.}
13 b412345d Florent Chuffart
  \item{rm_starter}{If \emph{TRUE} the file \emph{starter_name} will be deleted after the execution of all tasks.}
14 b412345d Florent Chuffart
  \item{log_dir}{Path to the \emph{log} directory.}
15 b412345d Florent Chuffart
  \item{bot_cache_dir}{the directory where task results are cached}
16 b412345d Florent Chuffart
  \item{nb_proc}{If not NULL fix the number of core on which tasks must be computed.}
17 b412345d Florent Chuffart
  \item{\dots}{Other arguments that will be passed to \emph{task_processor}.}
18 b412345d Florent Chuffart
}
19 b412345d Florent Chuffart
20 b412345d Florent Chuffart
21 b412345d Florent Chuffart
22 b412345d Florent Chuffart
\author{Florent Chuffart}
23 b412345d Florent Chuffart
24 b412345d Florent Chuffart
25 b412345d Florent Chuffart
26 b412345d Florent Chuffart
27 b412345d Florent Chuffart
\examples{
28 b412345d Florent Chuffart
29 b412345d Florent Chuffart
# We define a basic task_processor
30 b412345d Florent Chuffart
sum_a_b = function(task) {
31 b412345d Florent Chuffart
  return(task$a + task$b)
32 b412345d Florent Chuffart
}
33 b412345d Florent Chuffart
34 b412345d Florent Chuffart
# We define 9 tasks
35 b412345d Florent Chuffart
tasks = list()
36 b412345d Florent Chuffart
for (a in 1:3) {
37 b412345d Florent Chuffart
  for (b in 4:6) {
38 b412345d Florent Chuffart
    tasks[[length(tasks) + 1]] = list(a=a, b=b, out_filename=paste("sum_a_b", a, b, sep="_")) 
39 b412345d Florent Chuffart
  }
40 b412345d Florent Chuffart
}
41 b412345d Florent Chuffart
42 b412345d Florent Chuffart
# We execute the 3 tasks
43 b412345d Florent Chuffart
run_engine(tasks, sum_a_b)    
44 b412345d Florent Chuffart
45 b412345d Florent Chuffart
# We collect 9 task results
46 b412345d Florent Chuffart
for (a in 1:3) {
47 b412345d Florent Chuffart
  for (b in 4:6) {
48 b412345d Florent Chuffart
    out_filename = paste("sum_a_b", a, b, sep="_")
49 b412345d Florent Chuffart
    out_filename = paste("cache/", out_filename, ".RData", sep="")
50 b412345d Florent Chuffart
    load(out_filename)
51 b412345d Florent Chuffart
    print(task_result) 
52 b412345d Florent Chuffart
  }
53 b412345d Florent Chuffart
}
54 b412345d Florent Chuffart
55 b412345d Florent Chuffart
# Better way to do that
56 b412345d Florent Chuffart
apply(t(tasks), 2, function(task) {
57 b412345d Florent Chuffart
  out_filename = task[[1]]$out_filename
58 b412345d Florent Chuffart
  out_filename = paste("cache/", out_filename, ".RData", sep="")
59 b412345d Florent Chuffart
  load(out_filename)
60 b412345d Florent Chuffart
  print(task_result) 
61 b412345d Florent Chuffart
})
62 b412345d Florent Chuffart
63 b412345d Florent Chuffart
# Viewing statistics about the campain.
64 b412345d Florent Chuffart
bot_stats()
65 b412345d Florent Chuffart
66 b412345d Florent Chuffart
}