Copy and Paste  -   An Application to Copy/Paste Text  

 
S.No 5728 Name ..... Date/Time 20-Jun-2023 08:38:08 AM

Copy text from below
import numpy as np N = 100 # Size of the matrices # Generate random matrices A and B A = np.random.rand(N, N) B = np.random.rand(N, N) # Sequential matrix multiplication def matrix_multiplication(A, B): rows_A, cols_A = A.shape rows_B, cols_B = B.shape # Check if matrices can be multiplied if cols_A != rows_B: raise ValueError("Matrices dimensions are not compatible for multiplication.") # Initialize resulting matrix C C = np.zeros((rows_A, cols_B)) # Perform matrix multiplication for i in range(rows_A): for j in range(cols_B): for k in range(cols_A): C[i][j] += A[i][k] * B[k][j] return C # Perform matrix multiplication using sequential algorithm C_seq = matrix_multiplication(A, B) # Print the resulting matrix C print("Sequential matrix multiplication:") print(C_seq) from mpi4py import MPI # Initialize MPI comm = MPI.COMM_WORLD num_processes = comm.Get_size() rank = comm.Get_rank() # Scatter matrix A to all other processes if rank == 0: scattered_A = np.array_split(A, num_processes) else: scattered_A = None # Receive the scattered portion of matrix A local_A = comm.scatter(scattered_A, root=0) # Print the received portion of matrix A on each process print("Rank", rank, "received portion of matrix A:") print(local_A) # Scatter matrix B to all processes scattered_B = comm.bcast(B, root=0) # Print the received portion of matrix B on each process print("Rank", rank, "received portion of matrix B:") print(scattered_B) # Perform local matrix multiplication local_C = matrix_multiplication(local_A, scattered_B) # Print the resulting local matrix on each process print("Rank", rank, "local matrix multiplication result:") print(local_C)# Reduce the local matrix portions using MPI_Reduce with the MPI_SUM operation reduced_C = comm.reduce(local_C, op=MPI.SUM, root=0) # Print the resulting matrix C on process rank 0 if rank == 0: print("Parallel matrix multiplication result:") print(reduced_C) import time # Measure the execution time of sequential matrix multiplication start_time = time.time() C_seq = matrix_multiplication(A, B) end_time = time.time() seq_execution_time = end_time - start_time # Measure the execution time of parallel matrix multiplication start_time = time.time() local_C = matrix_multiplication(local_A, scattered_B) reduced_C = comm.reduce(local_C, op=MPI.SUM, root=0) end_time = time.time() parallel_execution_time = end_time - start_time # Print the execution times if rank == 0: print("Sequential execution time:", seq_execution_time) print("Parallel execution time:", parallel_execution_time)




comments powered by Disqus
NEW ENTRIES
S.No Name Entry Time/Date
5931 1111 23-Apr-2024 03:54:24 PM
5930 Savvy Cats 23-Apr-2024 06:52:03 AM
5929 listoclassob 22-Apr-2024 01:21:06 PM
5928 listofmap 22-Apr-2024 01:11:05 PM
5927 arrow inarro 22-Apr-2024 12:41:59 PM
5926 missing 21-Apr-2024 02:53:32 PM
5925 list of maps 16-Apr-2024 03:03:57 PM
5924 Micro 3 16-Apr-2024 11:57:26 AM
5923 Micro2 16-Apr-2024 11:53:20 AM
5922 Micro 16-Apr-2024 11:53:04 AM
5921 VRSefy 14-Apr-2024 06:56:37 PM
5920 Rogers Landw 08-Apr-2024 02:57:52 PM
5919 Frank Family 29-Mar-2024 03:50:35 PM
5918 Google Drive 27-Mar-2024 11:09:57 AM
5917 Google Drive 27-Mar-2024 10:41:56 AM
5916 google drive 25-Mar-2024 10:38:06 AM
5915 Stucco Champ 20-Mar-2024 10:55:56 PM
5914 B Physical 19-Mar-2024 10:52:02 AM
5913 guaranteelnc 12-Mar-2024 07:49:53 PM
5912 Spectrum Ele 12-Mar-2024 07:47:54 PM
5911 Spectrum 12-Mar-2024 01:30:08 PM
5910 Dr. Osman 11-Mar-2024 11:41:59 AM
5909 CHILD HOT 09-Mar-2024 08:02:39 AM
5908 H.-0-.T Vid 05-Mar-2024 08:20:33 AM
5907 Beyounce 04-Mar-2024 03:18:28 PM
5906 axiomintegra 03-Mar-2024 12:55:47 PM
5905 Comfort Ride 29-Feb-2024 04:03:14 PM
5904 David\'s RV P 26-Feb-2024 11:15:44 AM
5903 Child HOT 22-Feb-2024 06:43:26 AM
5902 Dumpsterfl 20-Feb-2024 01:33:22 PM

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 [Next] [Last]
 
web counter
web counter


To report any error messages or bugs, or other issues, please send email at: info@pakproject.com