Matrix Multiplication with 2 threads

Dependencies:   mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
agme
Date:
Fri Aug 08 00:56:15 2014 +0000
Commit message:
Initial Commit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 27261dbc7ba7 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Aug 08 00:56:15 2014 +0000
@@ -0,0 +1,56 @@
+#include "mbed.h"
+#include "rtos.h"
+
+
+double *A,*B,*C;
+int i,j,k,N;
+Serial pc(USBTX, USBRX); // tx, rx
+
+void process1_thread(void const *args)
+{
+    for(i=0; i<N/2; i++) {
+        for(j=0; j<N; j++) {
+            C[i*N+j]=0;
+            for(k=0; k<N; k++) {
+                C[i*N+j]= C[i*N+j] + A[i*N+k]*B[k+j*N];
+            }
+        }
+    }
+}
+
+void process2_thread(void const *args)
+{
+    for(i=N/2; i<N; i++) {
+        for(j=0; j<N; j++) {
+            C[i*N+j]=0;
+            for(k=0; k<N; k++) {
+                C[i*N+j]= C[i*N+j] + A[i*N+k]*B[k+j*N];
+            }
+        }
+    }
+}
+
+
+int main()
+{
+    
+    N=10;
+    //Inicialize matrix
+    for(i=0; i<N; i++) {
+        for(j=0; j<N; j++) {
+            A[i*N+j]=1;
+            B[i+j*N]=1;
+        }
+    }
+    
+    Thread thread1(process1_thread);
+    Thread thread2(process2_thread);
+    
+    //Print Results
+    for (i=0;i<N;i++){
+        for(j=0;j<N;j++){
+            pc.printf("%d ",C[i*N+j]); 
+        }
+         pc.printf("\n");
+    }  
+}
\ No newline at end of file
diff -r 000000000000 -r 27261dbc7ba7 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Fri Aug 08 00:56:15 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#34e80e862021
diff -r 000000000000 -r 27261dbc7ba7 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 08 00:56:15 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804
\ No newline at end of file