[Insight-users] Fast large matrix add
zlf
jxdw_zlf at yahoo.com.cn
Mon Oct 24 11:36:17 EDT 2011
Hi
I have two 4000x3000 matrics. Say matrix A and matrix C. I want to add the
two matrics. It tooks me 20ms now.
But in my application. I need it finished in 2ms!
Moreover, I cannot put the calculation in GPU because the data translation
between memory and GPU is time-costuming.
Anyway to accerlate the calculation in CPU?
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <conio.h>
int _tmain(int argc, _TCHAR* argv[])
{
short* a = new short[4000*3000];
short* b = new short[4000*3000];
short* c = new short[4000*3000];
clock_t cstart, cend;
double spend;
cstart = clock();
for(int i = 0 ; i < 1000;++i){
#pragma omp parallel for
for(int x = 0 ; x < 4000*3000;++x){
//for(int y = 0 ; y < 3000;++y){
short value = a[x] * 3000 + b[x];
c[x] = value;
//}
}
}
cend = clock();
spend = ((double)(cend-cstart)) / (double)CLOCKS_PER_SEC*1000/1000;
printf("spend: %f\n(ms)", spend);
return 0;
}
Thanks
Jerry
--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/Fast-large-matrix-add-tp6925448p6925448.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list