Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Architecture Multi-threaded Matrix Multiply

Similar presentations


Presentation on theme: "Computer Architecture Multi-threaded Matrix Multiply"— Presentation transcript:

1 Computer Architecture Multi-threaded Matrix Multiply
CSCE 513 Computer Architecture Computer Architecture Multi-threaded Matrix Multiply Topics Readings: Chapters 1-6, Appendicies C, B December 2, 2016

2 Your plan for the Multi-threaded MM
You should start and make sure you can compile and run phtread1.c Then you should take the matrix multiply c code that I sent out early in the semester. The matrices need to be global, i.e. declared outside of main or any other function so that all threads can access them. You should take matmult.c and modify it to be the taskCode. The matrix A and the product C should be partitioned into t = NumberOfThreads groups of size roughjly n/t rows Thread tid should know to start with row tid*(n/t)

3 Pthread1.c #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <assert.h> #define NUM_THREADS 5 void *TaskCode(void *argument) { int tid; tid = *((int *) argument); printf("Hello World! It's me, thread %d!\n", tid); /* optionally: insert more useful stuff here */ return NULL; }

4 int main (int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int thread_args[NUM_THREADS]; int rc, i; /* create all threads */ for (i=0; i<NUM_THREADS; ++i) { thread_args[i] = i; printf("In main: creating thread %d\n", i); rc = pthread_create(&threads[i], NULL, TaskCode, (void *) &thread_args[i]); assert(0 == rc); } /* wait for all threads to complete */ rc = pthread_join(threads[i], NULL); exit(EXIT_SUCCESS);

5

6

7

8

9

10

11

12

13

14


Download ppt "Computer Architecture Multi-threaded Matrix Multiply"

Similar presentations


Ads by Google