Unified Parallel C performance Optimization to properly layout data

Source: Internet
Author: User
Keywords Layout performance optimization unified
Tags aliyun allows users array block control data data distribution distributed

UPC language http://www.aliyun.com/zixun/aggregation/18736.html "> Allows the user to control how the data is laid out, and the layout of the data affects the performance of the program. This paper, through a series of program examples, makes the UPC language learners understand clearly how to layout the data reasonably from the angle of performance optimization.

Data distribution in UPC

Private Data distribution

In UPC, private data can only be accessed by the thread on which it resides. When declaring a private data, a copy of the variable is available in the private memory of each thread. As with several declaration statements in the list, these private data-distributed memory views are shown in Figure 1.

Listing 1. Private Data declaration

Suppose there are 4 threads. int A; int b int c[3]

Figure 1. Data distributed Memory view in Listing 1

Shared data distribution

In the UPC language, shared data can be accessed by any thread. When declaring a shared scalar variable, the variable is assigned to the shared memory of thread 0. When declaring a shared array, the UPC language introduces a layout type qualifier. The layout type qualifier determines how many contiguous shared elements are allocated to the shared memory space of the same thread. For example, the following declares an array of shared integers a:

shared [block_size] int a[number_of_elements];

[Block_size] is a layout type qualifier, and Block_size is a non-negative number that represents the size of the data distribution block. For example, when a layout type qualifier is [3], every three consecutive elements are allocated to a single thread's shared memory space for one block. The block size differs if the layout type qualifier is the following:

If the layout type qualifier does not exist, the declared shared array is allocated according to the chunk size of 1. If the layout type qualifier is [] or [0], and the chunk size is infinite, the declared shared array assigns all elements to the shared memory space of thread 0. If the layout type qualifier is [*], the declared shared array is allocated according to the chunk size (sizeof (array)/upc_elemsizeof (array) + THREADS-1)/THREADS.

Listing 2. Shared data declaration

Suppose there are four threads shared int X; Declares a shared integer data shared[2]int y[9]; Declares a shared integer type array containing 9 shared integer type elements shared [] float z[3]; Declares a shared floating-point type array with an infinity block size of 3 elements and a shared memory space at thread 0//

Figure 2. Data distributed memory view in Listing 2

Related Article

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.