The following tips of parallel programs:

Source: Internet
Author: User

We have the following experiences on multithreading and parallel processing in the past two days:

1 shared resource is a poison, especially when locks are frequently required. When the number of computing cores increases, the performance expansion is not obvious.

2. Try to use the ready-made parallel framework. Net TPL, C ++ opencl, and amp. These frameworks can form a thread pool, which can automatically give schedule the best number of threads, scheduling policies, and task allocation according to the current situation of the system. Enables the CPU to work at full capacity.

3. Use coarse-grained in parallel. Fine-grained will make the cost of the system creation and scheduling thread more time than the actual task execution time. Pay special attention to the recursive program, such as quiksort. If the division is unreasonable, the parallel time will be later than the sequential execution time.

4 I/O is the most time-consuming part. When multiple threads read and write multiple files at the same time, the performance will not be significantly improved, but may be reduced. I have to study it carefully, but I have not figured it out.

5. How to develop a non-blocking program requires further research.

6. Difference Between spinlock and lock mutex: The spinwait will not let the thread jump out of the kernel, but the thread will be called out if the mutex cannot wait.

7 find the bottleneck and tackle it.

8 Amdahl's law. The most efficient time in theory. Amdal's law specifies that if a calculated 1/s is sequential in nature, the maximum performance improvement will be limited by the factor S. The argument is as follows: the execution time of a parallel computing, TP, is the sum of the sequential part of the computing time and the parallel part of the computing time. If the time required for execution of the computing in sequence is ts, when there are P processors, TP can be expressed as S = N/[1 + (n-1) F]

Task [] tasks = new task [subcount];
For I = 0; I <subcount; I ++)
{
Task [I] = task. Factory. startnew (convert (sub ));
}


Task [] alltasks = tasks;

// Print completion notices one by one as tasks finish.
While (tasks. length> 0)
{
Taskindex = task. waitany (tasks );
// Progress bar updated.
Tasks = tasks. Where (t) => T! = Tasks [taskindex]). toarray ();
}

// Observe any exceptions that might have occurred.
Try
{
Task. waitall (alltasks );
}
Catch (aggresponexception AE)
{
...
}

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.