Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
asasas
#include <stdio.h> #include <time.h> #include <stdlib.h> #include <pthread.h> int a[18][16]; //first array int b[16][18]; //second array struct thread_info { int arow, bcol; // The matries a and b int c[18][18]; // The result: c = a*b }; typedef struct thread_info thread_info_arr; void *func(void *arg) { thread_info_arr *info; int k, arow, bcol, sum=0; int c[18][18]; info = (thread_info_arr *)arg; arow = info->arow; bcol = info->bcol; for(k=0; k <16;k++){ sum = sum + a[arow][k]*b[k][bcol]; } c[arow][bcol]= sum; sum=0; info->c[arow][bcol] = c[arow][bcol]; pthread_exit(NULL); } int main(void) { pthread_t thread[324]; thread_info_arr info[324]; int i,k,j,z=0; // int a[18][16]; //int b[16][18]; //Initialize A for(i = 0; i < 18; i++){ for(k = 0; k < 16; k++){ a[i][k] = (i+1)+(k+1); } } //Initialize B for(k = 0; k < 16; k++){ for(j = 0; j < 18; j++){ b[k][j] = (k+1)+(2*(j+1)); } } for(i=0; i<18; i++){ for(j=0; j<18; j++){ info[z].arow=i; info[z].bcol=j; if (pthread_create(&thread[z], NULL, &func, &info[z]) != 0) { printf("Error in creating thread\n"); exit(1); z = z+1; } } } for(z=0; z<324;z++){ pthread_join(thread[z], NULL); } //printf("Exec time for thread1 = %lf sec\n", info1.exec_time); //printf("%d %d",a[0][0],b[0][0]); pthread_exit(NULL); //main(); pointlessly trying to cycle. }
run
|
edit
|
history
|
help
0
Lab 11 v.05
20171116:FUNCIONES
18BCE2182 ASSESS_1 Q2-2
Add c
3-D array sum and search
add.c
bitwise operations
Name pipe
upper case letter.c
1, 2, 3, & 4-layer neural networks in C