Question

Trying to parallelize the outer loop of this matrix-matrix multiplication using OpenMP

I want to add pragma statement(s) to the code as well. //Calculating the product of the matrix for(int i=0; i<n; i++) for(int

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  parallel_for (int(0), int, [&](int i) { for(int j=0;j<n;j++) { mat_ans[i][j]=0; for (int k=0;k<n;k++){ mat_ans[i][j]+=(mat_1[i][k]*mat_2[k][j]); }}} replace the code with the above code.The outer loop will be divided into smaller tread using the paraller_for. 
Add a comment
Know the answer?
Add Answer to:
Trying to parallelize the outer loop of this matrix-matrix multiplication using OpenMP I want to add...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write an OpenMP program to to optimize matrix multiplication (matmul) code to run fast on a...

    write an OpenMP program to to optimize matrix multiplication (matmul) code to run fast on a single processor core We consider a special case of matmul: C := C + A*B where A, B, and C are n x n matrices. This can be performed using 2n3 floating point operations (n3 adds, n3 multiplies), as in the following pseudocode: for i = 1 to n for j = 1 to n for k = 1 to n C(i,j) = C(i,j)...

  • Why is my multiplication wrong when i do a matrix of 3 x 5 and 2...

    Why is my multiplication wrong when i do a matrix of 3 x 5 and 2 x 2? code below import java.util.*; public class matrix { public static void main(String[] args) { int m, n, i, j; Random rand = new Random(); Scanner scan = new Scanner(System.in); System.out.print("enter how many rows:"); m = scan.nextInt(); System.out.print("enter how many columns:"); n=scan.nextInt(); int matrix_1[][] = new int[m][n]; //Initialize matrixes int maritx_2[][] = new int[m][n]; int matrix_add[][] = new int[m][n]; int matrix_mul[][] = new...

  • I am trying to add a string command to my code. what am i doing wrong?...

    I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) {    int i, j;    int rowA, colA, rowB, colB;    int A[10][10], B[10][10];    int sum[10][10];    char str1[10];    printf("This is a matrix calculator\n");    //read in size from user MATRIX A    printf("Enter in matrix A....\n");    printf("\t#row = ");    scanf("%d", &rowA);    printf("\t#col = ");   ...

  • Given a matrix, clockwise-rotate elements in it. Please add code to problem3.cpp and the makefile. I...

    Given a matrix, clockwise-rotate elements in it. Please add code to problem3.cpp and the makefile. I have also given the main_problem3.cpp and problem3.h to test. problem3.cpp::: #include "problem3.h" // A function to rotate a matrix mat[][MAX] void rotatematrix(int m, int n, int mat[][MAX]) { // your code here    } Makefile::: all : problem3.o    g++ -o mainp3 # your code here problem3.o : problem3.h problem3.cpp    # your code here clean:    rm -f *.o mainp3 main_problem3.cpp::: #include <iostream>...

  • Using java, I am trying to recreate an arithmetic logic unit which performs an integer multiplication....

    Using java, I am trying to recreate an arithmetic logic unit which performs an integer multiplication. I should able to get an output like this: 387637653 x 366499587 = 142069039730149311 But I am not sure because something is wrong apparently. The algorithm of the program goes like: Test multiplier0 If multiplier0 = 0 Shift the multiplicand register left 1 bit Shift the multiplier register right 1 bit If multiplier0 = 1 Add multiplicand to product and place the result in...

  • i created a two dimensional matrix class which holds my object complex number. I am trying...

    i created a two dimensional matrix class which holds my object complex number. I am trying to overload the parenthesis () so that I can access and modify the value at specified location of the matrix. say matrix[a][b] = 5; and my_vals is a private member of the matrix class. What is the problem with my code //constructor & inlitilize dynamic array matrix::matrix(int rows, int cols) { complex** m_vals = new complex * [rows]; for (int i = 0; i...

  • Please I need help in C language, I am trying to modify the code per the...

    Please I need help in C language, I am trying to modify the code per the below instructions, but I am getting errors. Can't fgure it out. The attempted code modification and data file is privided below, after the instructions. Thank you. Instructions:                  1.      First, add a function named printMsg that displays a message, a greeting, or an introduction to the program for the user. Add a statement that calls that function from the main function when your program starts....

  • I need help fixing my code: In C++ *************** 1) I want to sum the digits...

    I need help fixing my code: In C++ *************** 1) I want to sum the digits of an n*n matrix 2) find the average I have completed the rest ****Do not use C++ standard library. You must use pointers and pointer arithmetic to represent the matrix and to navigate through it. MY CODE: (I have indicated at which point I need help) #include <iostream> using namespace std; void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp;...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • I need a program in c++ the same as below code but I want it to...

    I need a program in c++ the same as below code but I want it to prompt the user to enter the number of elements after that I want it to ask the user to enter the array elements #include<algorithm> #include<stdio.h> #include<string.h> #include<iostream> using namespace std; int a[50]={2,5,4,3}; bool x[100]; int N=4;//number of elements    int k=10;//target sum int sum;//current target sum int cmp(const void *a,const void *b) { return *(int *)b-*(int *)a; } void backtrace(int n) { if(sum>k) return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT