Function mosek::optimize_batch
source · pub fn optimize_batch(
israce_: bool,
maxtime_: f64,
numthreads_: i32,
task_: &[&mut Task],
trmcode_: &mut [i32],
rcode_: &mut [i32]
) -> Result<(), String>
Expand description
Optimize a number of tasks in parallel using a specified number of threads.
§Arguments
-
israce_
If nonzero, then the function is terminated after the first task has been completed. -
maxtime_
Time limit for the function. -
numthreads_
Number of threads to be employed. -
trmcode_
The termination code for each task.See Rescode
-
rcode_
The response code for each task.See Rescode
Full documentation: https://docs.mosek.com/latest/capi/alphabetic-functionalities.html#mosek.env.optimizebatch
Examples found in repository?
examples/parallel.rs (lines 63-68)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
fn parallel(files : Vec<FileOrText>) -> Result<(),String> {
// Create an example list of tasks to optimize
let mut tasks : Vec<(String,Task)> = files.iter().filter_map(|fname| {
let mut t = Task::new().unwrap();
match fname {
FileOrText::File(fname) => {
if let Err(_) = t.read_data(fname.as_str()) { None }
else {
t.put_int_param(mosek::Iparam::NUM_THREADS, 2).unwrap();
Some((fname.as_str().to_string(),t))
}
},
FileOrText::Text(data) => {
if let Err(_) = t.read_ptf_string(data.as_str()) { None }
else {
t.put_int_param(mosek::Iparam::NUM_THREADS, 2).unwrap();
Some(("-".to_string(),t))
}
}
}
}).collect();
let mut res = vec![0i32; tasks.len()];
let mut trm = vec![0i32; tasks.len()];
{
let taskrs : Vec<& mut Task> = tasks.iter_mut().map(|(_a,b)| b).collect();
// Size of thread pool available for all tasks
let threadpoolsize : i32 = 6;
// Optimize all the given tasks in parallel
mosek::optimize_batch(false, // No race
-1.0, // No time limit
threadpoolsize,
taskrs.as_slice(), // Array of tasks to optimize
trm.as_mut_slice(),
res.as_mut_slice())?;
}
for (resi,trmi,(fname,ti)) in izip!(res,trm,tasks.iter()) {
println!("Task {} res {} trm {} obj_val {} time {}",
fname,
resi,
trmi,
ti.get_dou_inf(mosek::Dinfitem::INTPNT_PRIMAL_OBJ)?,
ti.get_dou_inf(mosek::Dinfitem::OPTIMIZER_TIME)?);
}
Ok(())
}