Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Anutter juan
#include <stdio.h> #include <math.h> #include <sys/mman.h> #include <pthread.h> #include <malloc.h> #include <stdlib.h> double a[18][16]; //first array double b[16][18]; //second array double c[18][18]; // The result %how to pseudo this code? struct thread_info { int detail; // The difference is the stakes. }; %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; %information necessary to be passed is row of a and col of b. and which C value it is. for (i = 0; i < 18; i++) { for (j = 0; j < 18; j++) { for (k = 0; k < 16; k++) { sum = sum + a[i][k]*b[k][j]; } c[i][j] = sum; sum = 0; } } return(c); %or the pointer for C. } int main(int argc, char *argv[]) { pthread_t loads[NTHREADS]; int no_of_threads; int i,j; /% Might not be of any use either. %%%%%%%%%%%%borrowed from lab 3.3 - reduced to matrixes to simplify the code. pthread_t thread[]; thread_info_t info[]; info[].maxitr = (int)maxitr; info[].op = '+'; if (pthread_create(&thread[], NULL, &func, &info[]) != 0) { printf("Error in creating thread 1\n"); exit(1); } pthread_join(thread[], NULL); printf("Exec time for thread[] = %lf sec\n", info[].exec_time); pthread_exit(NULL); %/ %load.c was not useful. My apologises. 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++) { if (pthread_create(&loads[i], NULL, &compute_C_ij, &i) != 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
A_141128_MatricesSuma
709 lab 3.1
bit shift and mask
C_141113_euclides
pointer1
18BCE2182 ASSESS_1 Q1-8
Bitwise Operations
Practice Problem 7
Palindromo
htabprepa