Main Content

recreate

Create new job from existing job

Description

newjob = recreate(oldjob) 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,'Tasks',tasksToRecreate) creates a job object with tasks that correspond to tasksToRecreate. Because communicating jobs have only one task, this option only supports independent jobs.

example

newjob = recreate(oldjob,'TaskState',states) creates a job object with tasks that correspond to the tasks with State specified by states. Because communicating jobs have only one task, this option only supports independent jobs.

example

newjob = recreate(oldjob,'TaskID',ids) 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 job myJob.

newJob = recreate(myJob)               

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

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 job oldIndependentJob.

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:

  • An array of parallel.Task belonging to oldjob.

  • A 1 x N logical array, where N is the size of oldjob.Tasks, indicating the tasks in oldjob to be recreated.

  • A function handle that accepts oldjob.Tasks as an input argument. This function must return a 1 x N logical array indicating the tasks in oldjob to be recreated, where N is the size of oldjob.Tasks.

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

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