matrix-multiplication

matrix multiplication using Mpi_Scatter and Mpi_Gather

北慕城南 提交于 2019-12-30 11:00:10
问题 I newbie to mpi programming. I was trying to write matrix multiplication. Went through the post MPI Matrix Multiplication with scatter gather about matrix multiplication using scatter and gather routine. I tried modifying the code available on above post as below... #define N 4 #include <stdio.h> #include <math.h> #include <sys/time.h> #include <stdlib.h> #include <stddef.h> #include "mpi.h" void print_results(char *prompt, int a[N][N]); int main(int argc, char *argv[]) { int i, j, k, rank,

Speeding up element-wise array multiplication in python

核能气质少年 提交于 2019-12-29 04:00:07
问题 I have been playing around with numba and numexpr trying to speed up a simple element-wise matrix multiplication. I have not been able to get better results, they both are basically (speedwise) equivalent to numpys multiply function. Has anyone had any luck in this area? Am I using numba and numexpr wrong (I'm quite new to this) or is this altogether a bad approach to try and speed this up. Here is a reproducible code, thank you in advanced: import numpy as np from numba import autojit import

How to speed up matrix multiplication in C++?

↘锁芯ラ 提交于 2019-12-28 05:33:36
问题 I'm performing matrix multiplication with this simple algorithm. To be more flexible I used objects for the matricies which contain dynamicly created arrays. Comparing this solution to my first one with static arrays it is 4 times slower. What can I do to speed up the data access? I don't want to change the algorithm. matrix mult_std(matrix a, matrix b) { matrix c(a.dim(), false, false); for (int i = 0; i < a.dim(); i++) for (int j = 0; j < a.dim(); j++) { int sum = 0; for (int k = 0; k < a

how to optimize matrix multiplication (matmul) code to run fast on a single processor core

谁说我不能喝 提交于 2019-12-28 02:11:09
问题 I am working on parallel programming concepts and trying to optimize matrix multiplication example on single core. The fastest implementation I came up so far is the following: /* This routine performs a dgemm operation * C := C + A * B * where A, B, and C are lda-by-lda matrices stored in column-major format. * On exit, A and B maintain their input values. */ void square_dgemm (int n, double* A, double* B, double* C) { /* For each row i of A */ for (int i = 0; i < n; ++i) /* For each column

Thread Array Java Matrix

风格不统一 提交于 2019-12-25 16:51:03
问题 I have a code of matrix operations add, subtract, multiply. The code generates two matrices with random elements within the dimension the user states. My questions is that I have to create a thread for every element of the output Matrix. I tried using an array to store the threads, but it returns an error for "mul" which is the variable I used for the method that implements run. There are two different classes with the Thread array in the class of the main method of course and the next class

Multiplying large vectors and Out of memory. Type HELP MEMORY for your options

穿精又带淫゛_ 提交于 2019-12-25 09:47:42
问题 Actually this is what i am trying to do Ad=<100820x20164 double> and b= <100820x1 double> also Ad is sparse matrix and b is non-sparse .Below is the original Problem and i try to change the statement A=V'*V + y_0*y_0'; using the block processing technique as you told me , now the problem is on the assignment statement mentioned below. V=Ad; b_1=b; x_0=ones(size(V ,1) ,1); y_0=V'*x_0; A=V'*V + y_0*y_0'; b=V'*b_1 + dot(x_0,b_1)*y_0; %%%%%%%%% Modified using block processing below %%%%%% V=Ad; b

Matrix multiplication by row

倾然丶 夕夏残阳落幕 提交于 2019-12-25 02:27:11
问题 Is there any way to calculate matrix c faster? a=matrix(runif(10),2,5) b=matrix(runif(15),3,5) c=matrix(,nrow(a)*nrow(b),5) k=0 for(i in 1:nrow(a)){ for(j in 1:nrow(b)){ k=k+1 c[k,]=a[i,]*b[j,] } } 回答1: Here is my version: c1 = a[ rep(1:nrow(a), each = nrow(b)), ] * b[ rep(1:nrow(b), times = nrow(a)), ]; all.equal(c, c1); > TRUE 来源: https://stackoverflow.com/questions/24988345/matrix-multiplication-by-row

Own matrix class multiply operator

笑着哭i 提交于 2019-12-25 01:56:16
问题 I wrote an IntegerMatrix class to add my own methods to work with matrices. Now I've written a function like this: IntegerMatrix** IntegerMatrix::multiplyMatrix(IntegerMatrix** table2) (It's a double pointer because I'm holding a huge array of pointers to 4x4 2D arrays.) so I simply could do this: matrix1.multplyMatrix(matrix2) One little problem is the * isn't defined for my own class. So I thought to overload this operator that I could do something like this: sum += this->table[i][k] *

simplifying a computation, so it could be done using matrix operations

空扰寡人 提交于 2019-12-25 01:55:40
问题 The basic operation I have is an operation on two probability vectors of the same length. let's call them A,B. in R the formula is: t = 1-prod(1-A*B) that is, the result is a scalar, the (1-AB) is a point-wise operation, whose result is a vector whose i'th element is 1-a_i*b_i . The prod operator gives the product of the elements of the vector. The meaning of this (as you could guess) is this: suppose A is the probability for each of N sources of a disease (or other signal) to have a certain

Sum of product each row by a matrix

爷,独闯天下 提交于 2019-12-24 20:53:48
问题 I have a matrix A and a three-dims matrix B . I want to sum (by i ) A(i,:)*B(i,:,:) , but without loops by i . 回答1: I'll start by creating some random matrices similar to what you described: n = 4; m =3; A = rand(n,m); B = rand(n,m,5); 1) loop version: C = zeros(1,size(B,3)); for i=1:n C = C + A(i,:)*squeeze(B(i,:,:)); end basically it performs matrix multiplication of each row of A by the corresponding slice of B , and accumulates the sum. This is could be slighty improved by permuting the