Skip to content

Instantly share code, notes, and snippets.

@JordiCorbilla
Created August 13, 2016 23:20
Show Gist options
  • Save JordiCorbilla/e86da13f3e77085f5646b80f78ed9f31 to your computer and use it in GitHub Desktop.
Save JordiCorbilla/e86da13f3e77085f5646b80f78ed9f31 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
@Author: Jordi Corbilla
@Description: Parallel MPI Matrix Multiplication (NxN)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This file is part of https://github.com/JordiCorbilla/mpi4py-examples/blob/master/src/examples/matrix%20multiplication/matrixmultiplication.py
"""
#Loop through rows
t_start = MPI.Wtime()
for i in range(0, slice):
res = np.zeros(shape=(numberColumns))
if (slice == 1):
r = recv_data
else:
r = recv_data[i,:]
ai = 0
for j in range(0, numberColumns):
q = b[:,j] #get the column we want
for x in range(0, numberColumns):
res[j] = res[j] + (r[x]*q[x])
ai = ai + 1
if (i > 0):
send = np.vstack((send, res))
else:
send = res
t_diff = MPI.Wtime() - t_start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment