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