Cilk User Guide Study Notes (3) cilk execution model

Source: Internet
Author: User

Note:

User Guide: http://software.intel.com/zh-cn/forums/showthread.php? T000077996&o=a&s=lr(cilk_user_guide.pdf)

This document provides some learning notes for this User Guide (Chinese version), simplifies the process, and gives you a better understanding of the code. You can refer to the original document for more details.

The three keywords of cilk are easy to understand and use, but to really understand the execution of cilk and correct use of the complex situation, you need to understand the cilk execution model.

Key concepts:

Strand:

It is used to describe the serial part of a program. More accurately, strand is defined as a sequence of arbitrary commands that do not contain any parallel control structure ".

A strand that is not part of a longer strand is called the largest strand, that is, the strand whose start and end point are the parallel control structures.

Derivative and Synchronization:

Cilk program inclusionTwo parallel control structures-derivative (spawn) and synchronization (Sync).

Note: The parallel loop cilk_for is a simple way to break down a problem into multiple derivatives and syntaxes.

Note: In the cilk program, one derivative has only one input strand and two output strand. One synchronization has two or more input strand and only one output strand.

Strand Diagram:

The call relationship diagram or class hierarchy diagram is usually used to describe traditional serial programs. For a cilk parallel program, the strand graph is used to express the serial/parallel structure in a cilk program. It is a directed acyclic graph (DAG), where, strands indicates a straight line and an arc (edge), and the parallel control structure indicates a circular node (vertex ). Example:

Among them, 1234 are strands, and AB is a parallel control structure, where A is derivative, and B is synchronization.

Working hours and Span:

What is required to complete the programProcessor timeThe total number is the sum of all tag numbers. This value is defined as working hours.

SPAN, also known as the key path length, is the longest path from the start point to the end point of the program.

Generally, the execution time (processor time) of each longest strand can be indicated on the edge of the strand diagram above. Therefore, the working hours are the sum of the time of all edges, the span is the total time of the longest path from the start point to the end point. Obviously, the span is less than or equal to the working hours.

The meaning of man-hours is: if the program is executed on a single processor, it will run the time represented by man-hours.

SPAN indicates the time when the program runs in an ideal state (for example, when there is no scheduling overhead) And when an unlimited multi-processor is available.

Cilk ProgramAcceleration ratio and scalability:

Generally, a cilk program can be used to predict the acceleration ratio and scalability of a multi-processor system by working hours and spans. Assume that T (P) is the execution time of the Program on P processors, T (1) is the working hours, and T (∞) is the span. Generally, there is a law of work hours as follows:
T (p)> = T (1)/P
There are the following span laws:
T (p)> = T (∞)

The acceleration ratio of P processors is:
T (1)/t (P)

The maximum possible acceleration ratio is obtained on an unlimited number of processors.

The degree of parallelism is defined as the acceleration ratio for running on an unlimited number of processors. Therefore, the degree of parallelism can be expressed:
T (1)/t (∞)

Mappings between strand and worker threads:

Dag does not depend on the number of processors. The execution model describes how the scheduling program maps strand to the working thread. After parallel execution is introduced, multiple strand can be executed in parallel. However, in a cilk program, strand that can be executed in parallel is not necessarily executed in parallel. The scheduler dynamically makes a decision.

Reference: mappings between workers.

Like other parallel programming methods, the system willStrand ing to operating system threads. However, to ensureSerial SemanticsThe system will adopt some distinctive strategies when running cilk.

The cilk ing relationship should be understood as follows:

1. To ensure the serial semantics, the derived function is always executed on the same worker thread as the strand that enters the derivative node. If other worker threads are available at this time, the continuation part can be executed on another worker thread. We call thisPassword Extraction(Steal), that isThe continuation part is encrypted by the new worker thread..

2. After cilk_sync, program execution can continue from any worker thread that enters the synchronization point.

In short, its key ideas include:

After cilk_spawn, The subtask is always executed on the same working thread (that is, the system thread) as the caller.
After cilk_spawn, the continuation part can be executed on another worker thread. In this case, we call the continuation part encrypted by another worker thread.
After cilk_sync, program execution can continue from any worker thread that enters the synchronization point.

Exception Handling in cilk:

Cilk language extensions try to maintain C ++ Exception Processing semantics as much as possible. This usually requires that concurrency be defined when exceptions are waiting for processing, and that the program cannot depend on parallelism during Exception Processing. The exception handling logic is described as follows:

If an exception is thrown and not captured in a child task, the exception will be thrown again by the parent task at the next synchronization point.

If an exception is thrown for a parent task or another subtask, the first thrown exception in the serial execution sequence has priority. The logical back-to-back exceptions will be discarded. Currently, there is no mechanism to collect multiple exceptions thrown in parallel.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.