magistraleinformaticanetworking:spm:exercise1617spm
Questa è una vecchia versione del documento!
SPM 1617 Exercise and assignments
Matrix multiplication
Write e program that generates two N by N matrixes A and B and computes C, the result of the multiplication of A by B. The computation has to be performed by M threads, each working on a partition of C. Check the correctness of the result against result computed sequentially. Plot scalability curve for the program.
Hints
- use
int atoi(char *)
to convert the command line arguments to integers
int main(int argc, char * argv[]) { int n = atoi(argv[1]); int m = atoi(argv[2]); ... }
- use the
std::chrono
library to get time before and after the parallel computation and to compute the elapsed time:
std::chrono::time_point<std::chrono::system_clock> start, end; start = std::chrono::system_clock::now(); ... end = std::chrono::system_clock::now(); std::chrono::duration<double> elapsed_seconds = end-start;
- use plain
rand
to generate random numbers in the two matrixes:
srand(123); for(....) { ... = ((float) (rand() % MAX)) / ((float) RAND_MAX);
magistraleinformaticanetworking/spm/exercise1617spm.1476280740.txt.gz · Ultima modifica: 12/10/2016 alle 13:59 (8 anni fa) da Marco Danelutto