Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Working except for the thread part. LUL
#include <stdio.h> #include <math.h> #include <sys/mman.h> #include <pthread.h> #include <malloc.h> #include <stdlib.h> int a[18][16]; //first array int b[16][18]; //second array int c[18][18]; // The result //%how to pseudo this code? struct thread_info { int shape; // The difference is the stakes. int colour; // Out of place }; //%Completes the arthimetic for one element of a product of matrix multiplication. void *compute_C_ij(void *arg) { int i, j, k, sum; //col, row; //i = ; //is passed by the pthread call. //j = ; //distinguishes which cij being solved. //%information necessary to be passed is row of a and col of b. and which C value it is. sum = 0; for (k = 0; k < 16; k++) { sum = sum + a[i][k]*b[k][j]; } c[i][j] = sum; return(c); //%or the pointer for C. } int main(int argc, char *argv[]) { int i,j,k; for(k=0; k<324; k++){ pthread_t thread[k]; //Thread variables thread_info info[k]; //structs to be passed } double a[18][16]; //arrays double b[16][18]; // arrays //%initializing for(i=0; i<18; i++){ for(j=0; j<16; j++){ a[i][j] = i+j; } } for(i=0; i<16; i++){ for(j=0; j<18; j++){ b[i][j] = i+(2*j); } } //%this is from load.c Want to recycle the lines below to run the threads to solve for the matrix concurrently. for (i = 0; i < 18; i++) { for (j = 0; j < 18; j++) { thread_info.shape = i; thread_info.colour = j; if (pthread_create(&thread[i], NULL, &compute_C_ij, (void *)&info[i+j]) != 0) { printf("Error creating thread %d.%d\n", i, j); } } } pthread_exit(NULL); printf("The Result of matrix multiplication a * b is: \n"); for(i=0; i<18; i++){ for(j=0; j<18; j++){ printf("%d\t", c[i][j]); } printf("\n"); } printf("The Diagonal of matrix multiplication a * b is: \n"); for(i=0; i<18; i++){ printf("%d", c[i][i]); printf("\n"); } }
run
|
edit
|
history
|
help
0
20171030_TRIANGULO
AVANCE 1 TAREA M4 - PERLAS
18BCE2182 MIDTERM PART-B CRITICAL
Lab 6 mb
20171103_factorial
c. new one
Project 4 v.5
B_141205_funciones
150114_ArrayOrdenado
Array Struct, Call-By-Reference, Malloc, Free, Init, Destroy ... Example