Lec13a-Homework 4 Feedbackx
Download
Report
Transcript Lec13a-Homework 4 Feedbackx
COMP8330/7330/7336 Advanced Parallel
and Distributed Computing
Homework 4 Feedback
Dr. Xiao Qin
Auburn University
http://www.eng.auburn.edu/~xqin
[email protected]
Pthreads Awards
Third Place
• Xiao Li
2
Pthreads Awards
Second Place
• Bradley Morgan
• Carlos Lemus
3
Pthreads Awards
First Place
• Ananya Ravipati
• Sumeet Wilkhu
4
Statistics
• No submission: 1
• Late submission: 1
• Grade = 100: 5
• Grade < 90: 4
• Lowest Grade: 72
5
What Makes a Good Report?
• Carlos Lemus: makefile; the most professional code.
• Ravi Kapoor and Abdulrahman Khamis: excellent
performance evaluation.
• Bradley Morgan: The most professional report.
• Ananya Ravipati: Best algorithm design
• Ananya Ravipati: Best performance.
• Sumeet Wilkhu: a shell script to test your program.
6
• Sumeet Wilkhu: the most extensive experiments.
How to present experimental results?
7
How to present experimental results?
8
A good example from Sumeet Wilkhu
9
A good example from Xiao Li
10
A good example from Ananya Ravipati
11
Wrong Speedup Calculations
Sample 1
12
Wrong Speedup Calculations
Sample 2
10 threads
number
13
execution time
Speedup
100
1000
10000
100000
0
0.03
0.84
8.49
1
0.0033
0.00011
0.0047
1000000
71.99
0.0101
No Heading
• Didn't provide a heading at the top of your
code containing your name, Auburn Userid,
filename, and how to compile your code.
14
A good example from Sony Bullock
// Sony Bullock
// UserId: szb0088
// pprimes.cpp : Defines the entry point
// for the console application.
// Compile: $gcc pprimes.c -pthread -o
pprimes
// Run code using the following command
lines:
// ./pprimes or./pprimes num or./pprimes
num nthreads
// num is entered by user to determine
primes up to the num
// nthreads is the number of threads
15
A good example from
Bradley Morgan
// pprimes.c
//
// This program uses multithreading to calculate
all prime numbers
// from two to the user-specified upper bound,
using a user-specified
// number of threads.
//
// Compilation: gcc -lpthread pprimes.c -o pprimes
//
// Usage: pprimes <limit> [nthreads]
//
// Written by Bradley Morgan (morgaia) for COMP
7330 Homework 4
// Fall 2015, Dr. Qin, Auburn University
16
No Results
• no experimental results found in one report.
17
What is the problem?
void *runthread(void *param) {
int i,j, np = 0;
int ele = (long)param;
int upper = range;
for(i = 2; i < upper; i++) {
int flag= 0;
/* Check each number for divisibility */
for(j = 2; j < i; j++) {
int result = i % j;
if(result == 0) {
flag = 1;
break;
}
}
if(flag == 0) {
np++;
printf("%d \n", i);
}
}
18
Performance Problems
• Speedups < 1
• How to reduce the synchronization overhead?
19
void *thread_function(void *arg) {
int i,j,k,m,b;
b = *(int*)arg;
for ( i=0; i<b; i++) {
pthread_mutex_lock(&mymutex);
if(indx[i]==0){
m=myglobal[i];
k=(int)sqrt( (double)m );
for(j=2;j<=k;j++){
if(m%j==0)
break;
}
if(j>k){
indx[i] =2;
}
else{
indx[i] =1;
}
}
pthread_mutex_unlock(&mymutex);
}
return NULL;
20
}
A Bad Example
Suggested Data Structure
// Multiple-argument structure
typedef struct
{
unsigned int start;
unsigned int end;
unsigned int local_primes[MAX_SIZE];
int local = 0;
} args_t;
21
Suggested Data Structure
// Multiple-argument structure
typedef struct
{
unsigned int start;
unsigned int end;
unsigned int local_primes[MAX_SIZE];
int local = 0;
} args_t;
/*Array with arguments for each thread*/
args_t arguments[num_threads];
22
How to partition workload?
int step = total_num / num_threads;
for(int i = 0, k = 0; i < 100; i+=step, k++) {
// Setting the specific argument
arguments[k].start = i;
arguments[k].end = i + step;
// Creating the thread
pthread_create(&threads[k], NULL,
find_primes, &arguments[k]);
}
23