recreate - Create new job from existing job - MATLAB (original) (raw)

Create new job from existing job

Syntax

Description

`newjob` = recreate([oldjob](#mw%5F36828e51-bd70-46b2-89df-c8756cdcb3c8)) creates a new job object based on an existing job, containing the same tasks and options as oldjob. The old job can be in any state; the new job state is pending. If oldjob was created using batch, then MATLAB® automatically submits the new job.

example

`newjob` = recreate([oldjob](#mw%5F36828e51-bd70-46b2-89df-c8756cdcb3c8),'Tasks',[tasksToRecreate](#mw%5Fe2b31905-d60a-4205-a5e1-1c247a56a49c)) creates a job object with tasks that correspond totasksToRecreate. Because communicating jobs have only one task, this option only supports independent jobs.

example

`newjob` = recreate([oldjob](#mw%5F36828e51-bd70-46b2-89df-c8756cdcb3c8),'TaskState',[states](#mw%5F275da76b-c8d8-4d2f-a07e-af640ce139d5)) creates a job object with tasks that correspond to the tasks withState specified by states. Because communicating jobs have only one task, this option only supports independent jobs.

example

`newjob` = recreate([oldjob](#mw%5F36828e51-bd70-46b2-89df-c8756cdcb3c8),'TaskID',[ids](#mw%5F1c19c480-cfaf-40da-8e82-7dda6258ee7f)) creates a job object containing the tasks from oldjob that correspond to the tasks with IDs specified by ids. Because communicating jobs have only one task, this option only supports independent jobs.

example

Examples

collapse all

This approach is useful when tasks depend on a file that is not present anymore.

Create a new job using the default cluster profile. In this example, it is the local parallel pool.

cluster = parcluster; job = createJob(cluster);

Create several tasks. In particular, create a task that depends on a MAT file that does not exist.

createTask(job,@() 'Task1',1); createTask(job,@() load('myData.mat'),1);

Submit the job, and wait for it to finish. Because the MAT file in the second task does not exist, the job fails. If you call fetchOutputs on job to retrieve the results, you get an error. Check the error using the Error property of the corresponding task.

submit(job); wait(job); job.Tasks(2).Error

ans = ParallelException with properties:

 identifier: 'MATLAB:load:couldNotReadFile'
    message: 'Unable to find file or directory 'myData.mat'.'
      cause: {}
remotecause: {[1×1 MException]}
      stack: [1×1 struct]
 Correction: []

Create the MAT file referenced from the second task using the save function. To create a new job with the tasks that resulted in an error, use the 'Tasks' name-value pair in recreate, and provide the hasError function. If you want to select a different set of tasks, you can define your own function.

str = 'Task2'; save myData str newjob = recreate(job,'Tasks',@hasError);

Submit the new job, wait for its completion, and fetch the outputs. Because the MAT file now exists, the job does not fail.

submit(newjob); wait(newjob); out = fetchOutputs(newjob); out{1}

ans = struct with fields: str: 'Task2'

This example shows how to recreate the entire jobmyJob.

This example shows how to recreate an independent job, which has only pending tasks from the joboldIndependentJob.

newJob = recreate(oldIndependentJob,'TaskState','pending');

This example shows how to recreate an independent job, which has only the tasks with IDs 21 to 32 from the joboldIndependentJob.

newJob = recreate(oldIndependentJob,'TaskID',[21:32]);

This example shows how to find and recreate all failed jobs submitted by user Mary. Assume the default cluster is the one Mary had submitted her jobs to.

c = parcluster(); failedjobs = findJob(c,'Username','Mary','State','failed'); for m = 1:length(failedjobs) newJob(m) = recreate(failedjobs(m)); end

Input Arguments

collapse all

Original job to be duplicated, specified as a parallel.Job object.

Example: newJob = recreate(oldjob); submit(newJob);

Data Types: parallel.Job

Tasks to duplicate from oldjob, specified as:

To rerun tasks containing errors or warnings, use this syntax with the predefined functions @hasError andhasWarnings.

Example: newJob = recreate(oldjob,'Tasks',@hasError | @hasWarnings);

Data Types: parallel.Task | logical | function_handle

State of the tasks to duplicate, specified as a string or cell array of strings. states represents the state of the required tasks to recreate from oldjob. Valid states are 'pending', 'running','finished', and'failed'.

Example: newJob = recreate(oldJob,'TaskState','failed');

Data Types: char | string | cell

IDs of the tasks to duplicate from oldjob, specified as a vector of integers.

Example: newJob = recreate(oldIndependentJob,'TaskID',[1 5]);

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Version History

Introduced in R2014a