Cilk User Guide Study Notes (7) cilk running system API and cilk Summary

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.

1. cilk running system API

The header file cilk/cilk_api.h contains the declaration of cilk running functions and classes. In addition, Apis related to cilk merge CERs are defined in the corresponding header file. Cilk_api.h is another API definition interface for cilk runtime.

Cilk exposes fewer APIs, Which is why cilk is easy to use.

(1) _ cilkrts_set_param
Int _ cilkrts_set_param (const char * Name, const char * value );
This function allows programmers to control multiple parameters of the cilk running system. Its two string parameters constitute a name/value pair. The supported name values are as follows:
Nworkers: The parameter value specifies the number of worker threads that can be used. The default value is in decimal format. The value can also be expressed by the prefix 0x or 0 in hexadecimal notation or octal notation. If the program does not call this function, the number of worker threads is determined by the value of the environment variable cilk_nworkers.By default, the number of worker threads is the same as the number of processors.. This function is valid only when you call a function that contains cilk_spawn or cilk_for for the first time.

(2) _ cilkrts_get_nworkers
Int _ cilkrts_get_nworkers (void );
This function returns the number of worker threads allocated for processing cilk tasks.Freeze this quantityTo prevent _ cilkrts_set_paramd from modifying it. If it is called in a serial code, this function returns 1.
The id value of the worker thread is not necessarily in a continuous range.Therefore, the ID value of the worker thread may be greater than the return value of _ cilkrts_get_nworkers.

(3) _ cilkrts_get_worker_number
Int _ cilkrts_get_worker_number (void );
This function returns an integer representing the number of cilk worker threads that execute this function.
(4) _ cilkrts_get_total_workers
Int _ cilkrts_get_total_workers (void );
At a specific time, the cilk running system may allocate more working threads than the number of active working threads. This function returns the total number of worker threads, including those that are not in use. In other words, this function returns a value greater than the maximum id value that can be allocated to a worker thread. In typical cases, this value is slightly larger than the number of worker threads that actually execute cilk tasks.

These APIs help you understand the cilk execution model by analyzing the working thread ID.

2. cilk summary:

Main content:

Three keywords: cilk_spawn, cilk_sync, cilk_for

Data competition Reducer

Run API

Important:

Cilk execution model: When derived, derived functions run in the current worker thread, the remaining part of the current function runs on the new working thread (provided that the work password is indeed obtained ). The synchronized thread is random, which may be the original working thread or a new working thread. Therefore, the job password will cause thread migration.

Cilk_for: The Division strategy of the binary method is not derived by every iteration. Granularity.

To sum up, cilk contains less content and is less difficult to learn. The key lies in the understanding of the execution model. For more in-depth study, since cilk is already open-source, it is a good way to learn its principles and mechanisms through source code!

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.