CSC/ECE 506 Spring 2010/ch 2 aj/Data Parallel Programming: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 13: | Line 13: | ||
= Examples = | = Examples = | ||
// a simple code | |||
my_sum = 0; | |||
'''for''' (i = 0; i < a.length; i++) | |||
{ | |||
a[i] = a[i] * i; | |||
my_sum = my_sum + a[i]; | |||
} | |||
// data parallel programming: let each PE perform the same task on different pieces of distributed data | |||
pe_id = getid(); | |||
my_sum = 0; | |||
'''for''' (i = pe_id; i < a.length; i += number_of_pe) | |||
{ | |||
a[i] = a[i] * i; | |||
my_sum = my_sum + a[i]; | |||
} | |||
// data reorganization via message passing | |||
'''if''' (pe_id != 0) send_msg (0, my_sum); | |||
'''else''' | |||
'''for''' (i = 1; i < number_of_pe; i++) | |||
{ | |||
recv_msg (i, temp); | |||
my_sum = my_sum + temp; | |||
} | |||
// data reorganization via shared memory | |||
'''shared''' int sum; | |||
lock(); | |||
sum = sum + my_sum; | |||
unlock(); | |||
barrier; | |||
= References = | = References = |
Revision as of 03:41, 28 January 2010
Data-Parallel Programming Model
Introduction
Relationship with SIMD
Other Parallel Programming Models
Message Passing Programming Model
Examples
// a simple code my_sum = 0; for (i = 0; i < a.length; i++) { a[i] = a[i] * i; my_sum = my_sum + a[i]; }
// data parallel programming: let each PE perform the same task on different pieces of distributed data pe_id = getid(); my_sum = 0; for (i = pe_id; i < a.length; i += number_of_pe) { a[i] = a[i] * i; my_sum = my_sum + a[i]; }
// data reorganization via message passing if (pe_id != 0) send_msg (0, my_sum); else for (i = 1; i < number_of_pe; i++) { recv_msg (i, temp); my_sum = my_sum + temp; }
// data reorganization via shared memory shared int sum; lock(); sum = sum + my_sum; unlock(); barrier;
References
1) Old textbook
2) Internet article