Unified Parallel C

Yesterday, I was playing around UPC implementation from Berkeley. UPC (Unified Parallel C) is a parallel programming language based on the concept of partitioned shared memory. It is an extension of C for large scale parallel machines, including those with a common global address space (SMP and NUMA) and those with distributed memory (eg. clusters). There are a few opensource UPC implementations available out there:

\* GASNet UPC compiler from UC Berkeley
\* v1.1 MuPC compiler from Michigan Tech
\* Intrepid GCC UPC compiler


Compiling and installing Berkeley UPC on a new Solaris 10 machine is pretty straightforward, except I have to comment out the trunc() function in the emulate.cxx file, since it is already defined in Solaris 10. As with all programming languages, I got started with the Hello World example.
#include 
#include 
int main()
{
	printf("Thread %d of %d: Hello World\\n",MYTHREAD,THREADS);
	printf("done.\\n");
	return 0;
}
To compile it, I ran:
./bin/upcc –o hello hello.upc
Then to run it:
$ ./opt/bin/upcrun hello
UPCR: UPC thread 0 of 1 on x2100-three (process 0 of 1, pid=2923)
Thread 0 of 1: Hello World
done.
Simple and easy, but we are using only 1 thread here. We can recompile the code with the -pthread switch to enable threading.
./bin/upcc –o hello hello.upc -pthreads=2
Note that in the previous example, since I did not specify to compile with pthreads, running the example with -np > 1 will give an error. To run the threaded Hello example, just simply:
$ ./opt/bin/upcrun hello
UPCR: UPC threads 0..1 of 2 on x2100-three (process 0 of 1, pid=3997)
Thread 0 of 2: Hello World
done.
Thread 1 of 2: Hello World
done.
When compiling, by specify -pthreads=2 means that the default number of threads to use is 2. I can override this by adding -np=3 like this:
$ ./opt/bin/upcrun -np=3 hello
WARNING: Node 0 running more threads (3) than there are physical CPU's (2)
         enabling "polite", low-performance synchronization algorithms
UPCR: UPC threads 0..2 of 3 on x2100-three (process 0 of 1, pid=4009)
WARNING: Conflicting environment values for GASNET_COLL_GATHER_ALL_DISSEM_LIMIT (1024) and GASNET_COLL_GATHER_ALL_DISSEM_LIMIT_PER_THREAD (341)
WARNING: Using: 341
WARNING: Conflicting environment values for GASNET_COLL_EXCHANGE_DISSEM_LIMIT (1024) and GASNET_COLL_EXCHANGE_DISSEM_LIMIT_PER_THREAD (113)
WARNING: Using: 113
Thread 0 of 3: Hello World
done.
Thread 1 of 3: Hello World
done.
Thread 2 of 3: Hello World
done.
Note the warning. Since my Sun Fire X2100 has only 2 CPU, UPC warns that I'm running more threads than the CPUs available. Next testing, UPC with MPI.
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Melvin Koh

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today