Contenuto principale

isRunning

Determine whether pool activity monitor is running

Since R2025a

    Description

    tf = isRunning(monitor) returns logical 1 (true) if the ActivityMonitor object, monitor, is running and collecting pool activity data. Otherwise, the result is a logical 0 (false).

    example

    Examples

    collapse all

    Create an ActivityMonitor object to start collecting pool monitoring data. With default settings, parallel.pool.ActivityMonitor automatically starts an interactive parallel pool using the default profile if one does not exist.

    monitor = parallel.pool.ActivityMonitor;

    Run a parfor-loop to generate random numbers and store them in an array.

    data = zeros(1,100);
    parfor idx = 1:100
        data(idx) = rand;
    end

    Stop the activity monitor and retrieve the results collected during the parfor execution.

    monitorResults = stop(monitor);

    Determine if the activity monitor is running and collecting pool monitoring data.

    isRunning(monitor)
    ans = logical
       0
    
    

    Restart the activity monitor and determine if the activity monitor is running.

    start(monitor);
    isRunning(monitor)
    ans = logical
       1
    
    

    If you call the start function on an ActivityMonitor object that is already monitoring pool activity, MATLAB® discards any previously collected results. To prevent this, use the isRunning function in an if/else statement to check whether the monitor is already running before calling start.

    Create an ActivityMonitor object to collect monitoring data but do not start collecting data immediately.

    monitor = parallel.pool.ActivityMonitor(Start=false);

    Use an if/else statement to determine whether the activity monitor is running. If it is running, execute the parallel code. Otherwise, start the monitor first, then run the parallel code.

    if isRunning(monitor)
        runParallelCode;
    else
        start(monitor);
        runParallelCode;
    end

    Define a function that runs parallel computations using parfeval.

    function runParallelCode
    f(1:100) = parallel.FevalFuture;
    for idx = 1:100    
        f(idx) = parfeval(@(n) real(eig(randn(n))),1,5e2);    
    end
    maxFuture = afterEach(f,@max,1);
    wait(maxFuture);
    end

    Input Arguments

    collapse all

    Pool activity monitor, specified as an ActivityMonitor object.

    Example: monitor = parallel.pool.ActivityMonitor

    Output Arguments

    collapse all

    True or false result, returned as a 1 or 0 of data type logical.

    • The function returns 1 if the ActivityMonitor object is running and collecting pool activity data. To stop collecting pool activity data, use the stop function.

    • The function returns 0 if the ActivityMonitor object is not running and not collecting pool activity data. To start collect pool activity data, use the start function.

    Data Types: logical

    Version History

    Introduced in R2025a