Cilk User Guide Study Notes (6) Operating System Problems

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. Use other tools on the cilk Program

BecauseThe cilk program has STACK layout and calling rules different from the C/C ++ standard.Tools that are used in binary code (including memory check tools and code overwrite tools similar to valgrind) may not be used in cilk parallel programs. In many cases, you can run the program by using only one worker thread (by setting the environment variable cilk_nworkers to 1. If this does not work, you can use these tools on the serial version of The cilk program.

2. General interaction with operating system threads

When working with the operating system thread, remember the following points:
The worker thread is the operating system thread.
During runtime, the system allocates a "worker thread" set through the relevant mechanisms of the operating system.
The cilk program will not always use all available processors for 100%..

These points are easy to understand, and the worker thread will eventually be mapped to the operating system thread.

Cilk strands is not an operating system thread. The same cilk strand will not be migrated between working threads during running. However, after a cilk_spawn, cilk_sync, or cilk_for statement, the worker thread changes because these statements abort one or more strand and create one or more new strand statements. And,You cannot control which worker thread executes a specific strand..

The above content will affect a program in many ways. The most important thing is:

Do not use Windows Thread for local storage or Linux pthread for proprietary data, because the OS thread may change when the password is used.. As an alternative, you can use other programming skills, such as the cilk holder reducer discussed earlier.

Do not use the operating system lock or mutex lock across cilk_spawn, cilk_sync, or cilk_for statements, because only the locking thread can unlock the lock..

In short, these two points are easy to understand when we understand the cilk execution model. The cilk execution model determines these limits, for example, the strand derived from cilk runs on the current worder, but the synchronized thread may be the original worker or the new worder, this is the meaning of "The operating password acquisition OS thread may change.

3. MFC and cilk programs

This is the same as the above "changes may occur when the OS thread is used for password extraction", which is an actual example in MFC. That is:

The Microsoft Foundation Class (MFC) Library relies on local thread storage to map the packaging class to the GDI object handle. Cilk strand itself cannot always run on any specific thread, soParallel programs using cilk cannot safely call the MFC Function.

Of course, this does not mean that cilk cannot be used in MFC, but cilk can still be used to complete computing-intensive tasks through certain policies. The core is to isolate the cilk computing code from the UI-related code in MFC to prevent MFC from being unable to work due to OS thread changes. A simple understanding is to use MFC to create a local thread for computing (the main thread is the UI thread). In this way, the computing thread uses cilk for computation and derivative synchronization. In any case, does not affect the change of the main thread.

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.