Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F120798662
mult.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jul 7, 04:19
Size
799 B
Mime Type
text/x-c
Expires
Wed, Jul 9, 04:19 (2 d)
Engine
blob
Format
Raw Data
Handle
27209573
Attached To
R6658 PHPC CG Project
mult.cpp
View Options
#include <iostream>
#include <string>
#include <random>
#include <string>
#include <chrono>
#include <cstdlib>
#include <chrono>
using namespace std;
int main(){
int rows=1000;
int cols=rows;
double matrix[rows*cols];
double vector[rows];
for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
matrix[j+cols*i]=j+cols*i;
}
vector[i]=i;
}
clock_t begin = clock();
for(int a=0;a<1000;a++){
double result[rows];
for(int i=0;i<rows;i++){
double sum=0;
for(int j=0;j<cols;j++){
sum+=matrix[i*cols+j]*vector[j];
}
result[i]=sum;
}
}
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
printf("wall clock time (clock_t) = %.4gs\n", elapsed_secs);
return 0;
}
Event Timeline
Log In to Comment