scale up parfor-凯发k8网页登录

main content

scale up parfor-loops to cluster and cloud

in this example, you start on your local multicore desktop and measure the time required to run a calculation, as a function of increasing numbers of workers. the test is called a strong scaling test. it enables you to measure the decrease in time required for the calculation if you add more workers. this dependence is known as speedup, and allows you to estimate the parallel scalability of your code. you can then decide whether it is useful to increase the number of workers in your parallel pool, and scale up to cluster and cloud computing.

  1. create the function.

    edit mycode
    
  2. in the matlab® editor, enter the new parfor-loop and add tic and toc to measure the time elapsed.

    function a = mycode(a)
        tic
        parfor i = 1:200
            a(i) = max(abs(eig(rand(a))));
        end
        toc
    end
  3. save the file, and close the editor.

  4. on the parallel > parallel preferences menu, check that your default cluster is processes (your desktop machine).

  5. in the matlab command window, define a parallel pool of size 1, and run your function on one worker to calculate the elapsed time. note the elapsed time for a single worker and shut down your parallel pool.

    parpool(1);
    a = mycode(1000);
    elapsed time is 172.529228 seconds.
    delete(gcp);
  6. open a new parallel pool of two workers, and run the function again.

    parpool(2);
    a = mycode(1000);

    note the elapsed time; you should see that this now has decreased compared to the single worker case.

  7. try 4, 8, 12 and 16 workers. measure the parallel scalability by plotting the elapsed time for each number of workers on a log-log scale.

    plot showing the time elapsed when running the mycode function on parallel pools with 1, 2, 4, 8, 12, and 16 workers.

    the figure shows the scalability for a typical multicore desktop pc (blue circle data points). the strong scaling test shows almost linear speedup and significant parallel scalability for up to eight workers. observe from the figure that, in this case, we do not achieve further speedup for more than eight workers. this result means that, on a local desktop machine, all cores are fully used for 8 workers. you can get a different result on your local desktop, depending on your hardware. to further speed up your parallel application, consider scaling up to cloud or cluster computing.

  8. if you have exhausted your local workers, as in the previous example, you can scale up your calculation to cloud computing. check your access to cloud computing from the parallel > discover clusters menu.

    open a parallel pool in the cloud and run your application without changing your code.

    parpool(16);
    a = mycode(1000);

    note the elapsed time for increasing numbers of cluster workers. measure the parallel scalability by plotting the elapsed time as a function of number of workers on a log-log scale.

    plot comparing the time elapsed when running the mycode function on parallel pools with 1, 2, 4, 8, 12, and 16 workers when using a local machine and a cloud cluster.

    the figure shows typical performance for workers in the cloud (red plus data points). this strong scaling test shows linear speedup and 100% parallel scalability up to 16 workers in the cloud. consider further scaling up of your calculation by increasing the number of workers in the cloud or on a compute cluster. note that the parallel scalability can be different, depending on your hardware, for a larger number of workers and other applications.

  9. if you have direct access to a cluster, you can scale up your calculation using workers on the cluster. check your access to clusters from the parallel > discover clusters menu. if you have an account, select cluster, open a parallel pool and run your application without changing your code.

    parpool(64);
    a = mycode(1000);

    plot comparing the time elapsed when running the mycode function on parallel pools with 1, 2, 4, 8, 12, and 16 workers when using a local machine, a local cluster, and a cloud cluster.

    the figure shows typical strong scaling performance for workers on a cluster (black x data points). observe that you achieve 100% parallel scalability, persisting up to at least 80 workers on the cluster. note that this application scales linearly - the speedup is equal to the number of workers used.

    this example shows a speedup equal to the number of workers. not every task can achieve a similar speedup, see for example interactively run loops in parallel using parfor.

    you might need different approaches for your particular tasks. to learn more about alternative approaches, see choose a parallel computing solution.

tip

you can further profile a parfor-loop by measuring how much data is transferred to and from the workers in the parallel pool by using ticbytes and tocbytes. for more information and examples, see .

related topics

网站地图