# Matlab Job Manager
Manages computational jobs. Here, a job is a function (typically expensive to run) that is called with some input and returns some output. This Job Manager is useful if you have many such jobs to run (perhaps in parallel), or you want to cache the results of the function for the benefit of front end code such-as data visualisation.
This library provides:
* Memoisation cache. Previously computed results are loaded from the cache instead of being recomputed. The cache is automatically invalidated when the relevant code is modified.
* Parallel execution of jobs with:
* Matlab's Parallel Computing Toolbox, or
* A compute cluster running a Portable Batch System (PBS) scheduler, or
* The included job server that distributes tasks to remote workers over a network connection.
This framework applies to functions with the signature:
```matlab
result = solver(config, display_config);
```
where
* `result` is the output of the computation (typically a struct)
* `solver` is a function that implements the computation
* `config` is a struct that includes all the settings necessary to describe the task to be performed. Any setting that could influence the return value must be included in this structure so that the memoisation cache can identify when to return a previously saved result.
* `display_config` is a struct that includes settings that **cannot** influence the return value `result`. For example, this structure could specify how verbose the solver should be in printing messages to the command window.
To use this library, you must organise your solver according to that function template.
There are two ways to use this package:
1. The low-level interface to the memoisation cache. Use this if you implement your own execution framework but want to add memoisation.
2. The high-level interface for running jobs. This automatically takes advantage of the memoisation cache.
## Example usage
Basic example:
```matlab
% Prepare the configs to process
c1 = struct();
c1.solver = @solver_fn; % you must set the "solver" field to a function handle
...
c2 = ...;
c3 = ...;
configs = {c1, c2, c3}; % Prepare a cell array of configs to process
r = jobmgr.run(configs); % Jobs will run in parallel with the Matlab parfor loop
% The return value is a cell array of results.
% Results are memoised so that subsequent calls return almost immediately
```
A more advanced example using a Portable Batch System (PBS) cluster, which is an asynchronous execution method:
```matlab
configs = {c1, c2, c3}; % Prepare a cell array of configs to process
run_opts.execution_method = 'qsub'; % Use the qsub command to schedule the jobs on the cluster
run_opts.configs_per_job = 2; % Run two configs (in series) per qsub job
run_opts.allow_partial_result = false; % Throw an exception if the jobs are not yet finished running
r = jobmgr.run(configs, run_opts); % Submit the jobs
%
% The qsub method queues the jobs and returns immediately, throwing 'jobmgr:incomplete'.
%
% Run this code again later when the jobs are finished and then the return value will
% be a cell array of results.
```
## Installation
This code assumes that it will be placed in a Matlab package called `+jobmgr`. You must ensure that the repository is cloned into a directory with this name.
The recommended way to install is to add this as a git subtree to your existing project.
$ git remote add -f matlab-job-manager https://github.com/bronsonp/matlab-job-manager.git
$ git subtree add --prefix +jobmgr matlab-job-manager master
At a later time, if there are updates released that you wish to add to your project:
$ git fetch matlab-job-manager
$ git subtree pull --prefix +jobmgr matlab-job-manager master
If you do not intend to use git subtree, you can simply clone the repository:
$ git clone https://github.com/bronsonp/matlab-job-manager.git +jobmgr
### Job Server (Linux)
The optional job server (for remote execution) requires some C++ code to be compiled.
$ sudo apt-get install libzmq3-dev
$ cd +jobmgr/+netsrv/private
$ make
### Job Server (Windows)
The optional job server (for remote execution) requires some C++ code to be compiled. Run the `compile_for_windows.m` script in the `+jobmgr/+netsrv/private` directory.
## Using the high-level interface
**Summary:** Look in the `+example` folder and copy this code to get started.
Prerequisites:
1. The solver must implement the function signature above.
2. The solver must explicitly tag its dependencies so that the memoisation cache
can be cleared when these dependencies change. See the "Dependency
tagging" section for instructions.
3. The solver must accept a string input `display_config.run_name` which gives a descriptive label to each job. Typically, this would be printed at the beginning of any status messages displayed during calculations. Run names are passed to the job manager with a cell array in `run_opts.run_names`.
4. The solver must accept a logical input `display_config.animate` which is intended to specify whether to draw an animation of progress during the calculation. This defaults of `false` when running in the job manager. You can ignore this field if it is not relevant.
5. The solver should check for the presence of a global variable `statusline_hook_fn`. If this variable exists, the solver should periodically call this function with a short string indicating current progress towards solving the task. The job server displays a table of currently executing jobs, and this status appears next to the job. Additionally, the server can detect crashed clients if a specified time has passed since the last status update. Lost jobs can be resubmitted to a new client.
An example solver that implements this API is included in the `+example` folder.
## Using the low-level interface
Prerequisites:
1. The solver must implement the function signature above.
2. The solver must explicitly tag its dependencies so that the cache can be emptied when these dependencies change. See the "Dependency tagging" section for instructions.
3. Call the `check_cache` function first before any other functions are called. This will create a new empty cache directory, or delete old cache entries if the solver code has been modified.
Use the following functions:
* `check_cache` to delete old cache entries if the code has been changed.
* `struct_hash` to convert a config structure into a SHA1 hash for use with the `store`, `is_memoised`, and `recall` functions.
* `store` to save a value to be recalled later
* `is_memoised` to check whether a saved value exists in the cache
* `recall` to recover a previously stored item.
## Dependency tagging
If you modify your code, then the memoisation cache needs to be cleared so that new results are calculated using the new version of your code. If your solver is fully self-contained, then you don't need to do anything. On the other hand, if your solver is split up into multiple M files, then you need to tag file dependencies.
The example code in the `+example` folder demonstrates how to do this.
File dependencies are tagged by inserting comments into your code:
% +FILE_DEPENDENCY relative/path/to/file.m
% +FILE_DEPENDENCY relative/path/*.m
% +MEX_DEPENDENCY path/to/mex/binary
You can use wildcards as indicated above. Tags with `FILE_DEPENDENCY` refer to text files (i.e. Matlab code). Tags with `MEX_DEPENDENCY` are a special case for MEX code. You must specify the path to the MEX binary *without* any file extension. The file extension as appropriate for your system is automatically appended to the file. For example, the above example would match `binary.mexa64` on Linux, and `binary.mexw64` on Windows.
## Execution methods
The method used to run the jobs is specified in the `run_opts.execution_method` field (in the second argument to `jobmgr.run`). The following execution methods are defined:
### Matlab's Parallel Computing Toolbox (p
Xs_layla
- 粉丝: 1370
- 资源: 195
最新资源
- 抽水蓄能电站混合发电系统调峰经济调度模型研究:粒子群算法的应用与调度方案优化,抽水蓄能电站的最佳调度方案研究 参考文献:抽水蓄能电站的最佳调度方案研究 非完全复献 matlab?粒子群算法 主要内容:
- 局部遮阴环境下光伏MPPT仿真模型的粒子群优化算法研究,局部遮阴光伏MPPT仿真模型-粒子群算法 ,核心关键词:局部遮阴光伏; MPPT仿真模型; 粒子群算法; 优化算法 ,局部遮阴下光伏MPPT的粒
- 两级式单相光伏并网系统:BOOST电路MPPT控制与前级桥式逆变SPWM调制及双闭环控制并网效果展示,两级式单相光伏并网仿真 前级采用BOOST变电路,通过电导增量法MPPT控制实现最大功率点跟踪
- "常用PLC电气图纸与CAD电气原理图库:三菱、欧姆龙等品牌的实用图库与快速设计工具",常用PLC电气图纸,CAD电气原理图常用画法,60多套,有三菱,欧姆龙,西门子,基恩士,经验成功应用案例,元器件
- 基于IEEE 9节点三机九节点系统的Matlab Simulink仿真模型:电压观测与扩展研究,支持向量与离散模式,IEEE 9节点 三机九节点系统 Matlab simulink仿真 该模型自己搭
- COMSOL软件模拟环状流管道中球阀开度对速度场、压力场及阀门流阻特性的影响分析,comsol软件 环状流管道中球阀开度对速度场,压力场,阀门流阻特性的影响 就是提取数据对速度场,压力场,阀门流阻特性
- 基于S7-200 PLC与MCGS组态的运料小车控制:梯形图程序详解、接线图与IO分配及组态画面展示,No.1160 基于S7-200 PLC和MCGS组态的运料小车控制系统 带解释的梯形图程序,接线
- EPLAN电气元件库大全:含部件宏、EDZ格式及众多品牌低压电器,1:1实物对应,便捷布局,一站式采购 ,EPLAN史上最全部件库,部件宏,EDZ格式,大小合适导入容易 部件包含图片宏,尺寸宏,有西门
- "并联型有源滤波器APF的Matlab仿真模型:采用ip-iq谐波检测与滞环电流控制及PI直流电压调控",并联型有源滤波器,APF,matlab仿真模型 谐波检测采用ip-iq方法,电流控制是滞环控
- IPMSM模型中的MTPA控制策略:采用牛顿迭代法的精确控制研究,该模型为IPMSM的MTPA控制,MTPA采用牛顿迭代法对关 ,核心关键词:IPMSM; MTPA控制; 牛顿迭代法; 关联关系,"I
- "Buck变换器系列仿真:平均电流控制、负载跳变与双闭环PI控制的性能探究及学习指南",Buck变器系列仿真 包括平均电流控制,,负载跳变及闭环性能测试,双闭环PI控制 模型简单易懂,适合小白学习
- 永磁同步电机SIMULINK仿真下的MRAS无传感器控制策略探索,永磁同步电机+SIMULINK+MRAS无传感器控制 A1 暂无文档 ,核心关键词:永磁同步电机; SIMULINK; MRAS无传感
- 有源电力滤波器(并联型APF)针对非线性负载应用场景的电流优化控制 含非线性负载时电流THDr显著下降,滞环控制与三角波比较控制效果对比 ,有源电力滤波器(并联型APF) 应用场景:含非线性负载时 非
- "龙讯方案之HDMI转EDP高清接口技术,1920x1080@60Hz全规格支持,全套资料、原理图、PCB及源码资源一应俱全",lt9721龙讯方案,hdmi转edp,1920*1080-60,可以提
- 基于虚拟同步控制技术的双馈风机多端MMC阻抗建模验证与扫频分析程序(附讲解与仿真模型),扫频法 阻抗扫描 阻抗建模验证 正负序阻抗 逆变器 同步控制 VSG 复现 双馈风机MMC 电压源型VSG阻抗建
- 基于Matlab仿真的声源定位算法及STM32F4实现源码:高精度定位达0.013米,2022声源定位相关资料及代码 内附声源定位算法基本原理及matlab仿真原理及实现方法; stm32f4实现源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈