Permalink
Browse files

updated for git and 3.0.y

  • Loading branch information...
1 parent e97df19 commit 66102a7372d8ab0c5aea34a4b496d5b06087ec5a @strassek strassek committed Sep 6, 2011
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -104,7 +104,7 @@ void eval_rules (struct life_t * life)
int ** grid = life->grid;
int ** next_grid = life->next_grid;
- #pragma omp parallel for private(neighbors,j,k,l)
+ #pragma omp parallel for private(neighbors,i,j,k,l)
for (i = 1; i <= ncols; i++) {
for (j = 1; j <= nrows; j++) {
neighbors = 0;
@@ -325,7 +325,7 @@ void randomize_grid (struct life_t * life, double prob)
int nrows = life->nrows;
#pragma omp parallel for private(i,j)
- for (i = 1; i <= ncols; i++) {
+ for (i = 1; i <= ncols; i++) {
for (j = 1; j <= nrows; j++) {
if (rand_double() < prob)
life->grid[i][j] = ALIVE;
@@ -13,7 +13,7 @@
# NO_X11 = 1
-CC = gcc
+CC = gcc -O3
LIBS += -lm
CFLAGS += -fopenmp
@@ -7,15 +7,15 @@
*The Shodor Education Foundation, Inc. *
* *
*Updated 2010, Tiago Sommer Damasceno and *
- * The Shodor Education Foundation, Inc. *
+ * The Shodor Education Foundation, Inc. *
* *
*setupWindow modified from the tutorial on*
*http://tronche.com/gui/x/xlib-tutorial/ *
* by Christophe Tronche *
*******************************************/
#include "Life.h"
#include <stdio.h>
-#include <stdlib.h>
+#include <stdlib.h>
void free_video(struct life_t * life)
{
@@ -144,6 +144,8 @@ void do_draw(struct life_t * life)
int rank_x = 12; // X coordinate for rank display
int rank_y = 23; // Y coordinate for rank display
+ int cell;
+
sprintf(string,"%d", rank);
XSetForeground(d->dpy, d->gc, d->deadColor);
@@ -157,7 +159,7 @@ void do_draw(struct life_t * life)
y1 = (j-1)/(nrows+1) * d->height;
if (life->grid[i][j] >= ALIVE) {
- int cell = life->grid[i][j];
+ cell = life->grid[i][j];
if (cell>NUM_GRAYSCALE-1) cell=NUM_GRAYSCALE-1;
XSetForeground(d->dpy, d->gc, d->Xgrayscale[cell].pixel);
} else {
@@ -13,7 +13,7 @@
# NO_X11 = 1
-CC = gcc
+CC = gcc -O3
LIBS += -lm
CFLAGS +=
View
@@ -1,10 +1,10 @@
default: matmulti
matmulti.o: matmulti.c
- gcc -O3 -c matmulti.c -fopenmp
+ gcc -O3 -ftree-vectorizer-verbose=7 -std=c99 -c matmulti.c -fopenmp
matmulti: matmulti.o
- gcc -O3 -o matmulti matmulti.o -fopenmp
+ gcc -O3 -ftree-vectorizer-verbose=7 -std=c99 -o matmulti matmulti.o -fopenmp
clean:
rm -f *.o matmulti
View
@@ -6,7 +6,7 @@
#define PRINTMAX 10
#define CHUNK 1
-void print_array(TYPE **A, int order, char label){
+void print_array(TYPE *A, int order, char label){
int i, j;
if(order > PRINTMAX)
@@ -16,14 +16,14 @@ void print_array(TYPE **A, int order, char label){
for(i = 0; i < order; i++){
for(j = 0; j < order; j++)
- printf("[%hd] ", A[i][j]);
+ printf("[%hd] ", A[i*order+j]);
printf("\n");
}
}
int main (int argc, char *argv[])
{
- TYPE **A, **B, **C;
+ TYPE * restrict A, * restrict B, * restrict C;
int i, j, k, order;
int tid;
@@ -34,49 +34,30 @@ int main (int argc, char *argv[])
order = atoi(argv[1]);
- A = (TYPE**)calloc(order, sizeof(TYPE*));
- B = (TYPE**)calloc(order, sizeof(TYPE*));
- C = (TYPE**)calloc(order, sizeof(TYPE*));
+ A = (TYPE*)calloc(order * order, sizeof(TYPE));
+ B = (TYPE*)calloc(order * order, sizeof(TYPE));
+ C = (TYPE*)calloc(order * order, sizeof(TYPE));
if(!A || !B || !C){
fprintf(stderr, "ERROR: Out of memory\n");
exit(EXIT_FAILURE);
}
-
- for(i = 0; i < order; i++){
- A[i] = (TYPE*)calloc(order, sizeof(TYPE*));
- B[i] = (TYPE*)calloc(order, sizeof(TYPE*));
- C[i] = (TYPE*)calloc(order, sizeof(TYPE*));
- if(!A[i] || !B[i] || !C[i]){
- fprintf(stderr, "ERROR: Out of memory\n");
- exit(EXIT_FAILURE);
- }
- }
+
#pragma omp parallel shared(A,B,C,order) private(i,j,k,tid)
{
- tid = omp_get_thread_num();
-
- if(!tid)
- printf("Using %d threads on %d processors...\n", omp_get_num_threads(), omp_get_num_procs());
- #pragma omp for schedule(dynamic,CHUNK)
- for(i = 0; i < order; i++){
- if(order <= PRINTMAX)
- printf("[thread %d] initializing row %d\n", tid, i);
- for(j = 0; j < order; j++){
- A[i][j] = rand() % 10;
- B[i][j] = rand() % 10;
- C[i][j] = 0;
- }
+ #pragma omp for
+ for(i = 0; i < order * order; i++){
+ A[i] = 7;
+ B[i] = 7;
+ C[i] = 0;
}
+
- #pragma omp for schedule(dynamic,CHUNK)
- for(i = 0; i < order; i++){
- if(order <= PRINTMAX)
- printf("[thread % d] calculating row %d\n", tid, i);
- for(j = 0; j < order; j++)
- for(k = 0; k < order; k++)
- C[i][j] += A[i][k] * B[k][j];
- }
+ #pragma omp for
+ for(i = 0; i < order; i++)
+ for(k = 0; k < order; k++)
+ for(j = 0; j < order; j++)
+ C[(i*order)+j] += A[(i*order)+k] * B[(k*order)+j];
}
print_array(A, order, 'A');
View
@@ -1,10 +1,10 @@
default: prog
dynArray.o: dynArray.c dynArray.h
- gcc -Wall -ansi -c dynArray.c
+ gcc -O3 -march=atom -Wall -ansi -c dynArray.c
primes.o: primes.c primes.h
- gcc -Wall -ansi -c primes.c
+ gcc -O3 -march=atom -Wall -ansi -c primes.c
prog: dynArray.o primes.o main.c
- gcc -Wall -ansi -o prog dynArray.o primes.o main.c -lm
+ gcc -O3 -march=atom -Wall -ansi -o prog dynArray.o primes.o main.c -lm
clean:
rm dynArray.o
rm primes.o
@@ -4,7 +4,7 @@
#include <time.h>
#include <pthread.h>
#include "primes.h"
-#define NUM_THREADS 8
+#define NUM_THREADS 2
void print_results(struct Data *data){
int i, size;
@@ -24,6 +24,7 @@ int main (int argc, const char *argv[]) {
startTime = time(NULL);
data->lock = 0;
for(i = 2; i <= upperBound; i++){
+ printf("%d\n", i);
while(data->lock == 1) ;
data->lock++;
data->tested = i;
Submodule primesSieve deleted from 7252d7
Binary file not shown.
View
@@ -27,7 +27,7 @@ int main (int argc, char *argv[])
printf("Thread %d starting...\n",tid);
#pragma omp for schedule(dynamic, chunk)
- for(i = 3; i < ubound; i++){
+ for(i = 3; i < ubound; i += 2){
test = (int)sqrt((double)i);
for(j = 2; j <= test; j++){
if(i % j == 0){
@@ -1,10 +1,10 @@
default: primes
primes.o: primes.c
- gcc -c primes.c -fopenmp -lm
+ gcc -O3 -march=atom -c primes.c -fopenmp -lm
primes: primes.o
- gcc -o primes primes.o -fopenmp -lm
+ gcc -O3 -march=atom -o primes primes.o -fopenmp -lm
clean:
rm -f *.o primes
@@ -4,6 +4,9 @@
#include <stdlib.h>
#include <math.h>
+#define TRUE 1
+#define FALSE 0
+
int NUM_THREADS;
int UBOUND;
@@ -12,20 +15,21 @@ pthread_mutex_t mutexsum;
void *findPrime(void *param)
{
- int i, j, test, tid, runningCount = 0;
+ int i, j, test, tid, isprime = TRUE;
+ int runningCount = 0;
tid = (int)param;
for(i = (2 * tid) + 3; i < UBOUND; i += (2 * NUM_THREADS)){
test = (int)sqrt((double)i);
for(j = 2; j <= test; j++){
if(i % j == 0){
- runningCount--;
+ isprime = FALSE;
break;
}
}
- if(i != UBOUND){
+ if(isprime)
runningCount++;
- }
+ isprime = TRUE;
}
pthread_mutex_lock(&mutexsum);
kPrimeCount += runningCount;
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 66102a7

Please sign in to comment.