Detailed unified Parallel c pointer type, pointer algorithm

Source: Internet
Author: User
Keywords Unified pointer type pointer algorithm
Tags aliyun data html http listing memory type

Pointer types in the UPC language

The UPC language divides the data into shared and private types. The data that a pointer points to may be a shared type or a private type, and the pointer itself can be either a shared type or a private type. Therefore, there are four types of pointers in the UPC language, see Figure 1

Point to private data private type pointer to http://www.aliyun.com/zixun/aggregation/6267.html "> shared data private type pointer to private data share type pointer to shared data share type pointers

Figure 1. UPC language pointer type

Point to private data private type pointer

The P1 pointer in Figure 1 is a private type pointer to private data. The pointer is similar to a normal pointer in C language. When declaring one such pointer, the UPC language allocates memory for the copy of the pointer in the private memory of each thread, that is, each thread has a copy of the pointer. This pointer can be used to access private data for a thread. For example, the following statement declares an indicator pointing to a private data private type:

int *p1;

Listing 1. Point to private data private type pointer

# include <upc.h>/assume 2 threads to run the program # include <stdio.h> # include <<stdlib.h> int a=-1; void Main () {int *p1; if (mythread = 1) {//P1 points to dynamically allocated private memory. P1=malloc (1*sizeof (int)); *p1=1; else {//P1 point to variable A. p1=&a;} printf ("th=%d,*p1=%d\n", MYTHREAD,*P1); }

Figure 2. Listing 1 Program Memory view

Figure 3: Listing 1 Program output

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.