|
Boost : |
From: nisha kannookadan (nishak44_at_[hidden])
Date: 2007-12-04 08:31:39
Hey Steven Thanks for ur advices. I already had posted an updated code, which doesnt return a matrix and where I use pass by reference. I bought also a c++ book, hope to find some help there too.
But thanks a lot.
Nisha K
> To: boost_at_[hidden]> From: royalstream_at_[hidden]> Date: Mon, 3 Dec 2007 17:09:22 -0600> Subject: Re: [boost] C++ Performance> > Objects are getting copied over and over again, that is a big part of the > problem.> That is not the right way to do C++ if you want to get top performing code.> > With that said, you say you are a newbie so IMHO your options are:> > (A) Learn some more about C++ and use techniques (such as expresion > templates) to aviod all the copying around.> (B) Stick to basic C++ but change the way your code works (more on this > later)> (C) Stick to MATLAB> > As far as option (B), try creating your objects once and then passing them > by reference to the actual operations.> So, instead of having an itrans() function that returns a new matrix, make > it write the result to an output parameter and return nothing.> Not very pretty, I know, but if you want pretty go for option (A) or (C).> > I've used option (A) for something similar.> I have some Matrix/Vector classes that support intuitive syntax (X = Y * W) > yet they avoid the memory copies using expression templates. I also wrapped > Intel's MKL Library. As far as performance goes, Intel MKL library gives me > an edge when the matrixes are not tiny. For tiny matrixes my own hand > written code performs faster (because it avoids calling their library which > has some little overhead).> > But honestly, there's nothing wrong with using output parameters and keeping > things simple.> > Regards,> > Steven> > > > "nisha kannookadan" <nishak44_at_[hidden]> wrote in message > news:BAY122-W16E24F4B48411F2554E94FD97F0@phx.gbl...> >> > Wow, Im very impressed, I already got so much answers. Thanks a lot.> > I didnt realize, that there are different lists, sorry.> >> > The Code is quite huge. But I post here, a part, which takes quite a lot > > of time: These are two methods for wavelet transformations:> >> >> > matrix Wavelet::ttrans(matrix At, int level)> > {> > matrix cfe1, cfe2, cfo, cfe, c, d;> > int N,s2;> >> > N = (At.size1()+1)/2;> > s2 = At.size2();> > zero_matrix zer(N,s2);> >> > for (int ii = 1; ii <= level; ii++)> > {> > cfo.resize(N,s2,false);> > cfe.resize(N-1,s2,false);> > c.resize(N-1,s2,false);> > d.resize(N,s2,false);> > cfo.assign(subslice(At, 0,2,N, 0,1,s2));> > cfe.assign(subslice(At, 1,2,N-1, 0,1,s2));> >> > c.assign(cfe + (subrange(cfo, 0,N-1, 0,s2)+subrange(cfo, 1,N, 0,s2))*0.5);> >> > zer.resize(N,s2,true);> > cfe1.resize(N,s2,false);> > cfe2.resize(N,s2,false);> > cfe1.assign(zer);> > cfe2.assign(zer);> >> > (subrange(cfe1, 0,N-1, 0,s2)).assign(cfe);> > (subrange(cfe2, 1,N, 0,s2)).assign(cfe);> > d.assign(cfo-(cfe1+cfe2)*0.5);> >> > (subrange(At, 0,N-1, 0,At.size2())).assign(c);> > (subrange(At, N-1,2*N-1, 0,At.size2())).assign(d);> >> > N = N/2;> > }> >> > cfe1.clear();> > cfe2.clear();> > cfo.clear();> > cfe.clear();> > c.clear();> > d.clear();> >> > return At;> >> > }> >> > matrix Wavelet::itrans(matrix At,int level)> > {> > matrix inv_M,tmp;> > vector f1,f2;> > int N,m;> >> > N = (At.size1()+1)/2;> > scalar_vector e(2*N-1,1);> > scalar_vector f(2*N-2,0.5);> > m = At.size2();> >> > for (int ii=1; ii<=level; ii++)> > {> >> > e.resize(2*N-1,true);> > f.resize(2*N-2,true);> > f1 = f;> > f2 = f;> > for(int jj = 0; jj < 2*N-3; jj = jj+2)> > {> > f2(jj) = -0.5;> > f1(jj+1) = -0.5;> > }> >> > inv_M.resize(2*N-1,2*N-1,false);> > inv_M = MVHF::tri_inverse(e,f1,f2);> > tmp.resize(2*N-1,m);> > tmp.assign(prod(inv_M,subrange(At, 0,2*N-1, 0,m)));> >> > (subrange(At, 0,N-1, 0,At.size2())).assign(subslice(tmp, 1,2,N-1, > > 0,1,tmp.size2()));> > (subrange(At, N-1,2*N-1, 0,At.size2())).assign(subslice(tmp, 0,2,N, > > 0,1,tmp.size2()));> >> > N = N/2;> > }> >> > inv_M.clear();> > tmp.clear();> > f1.clear();> > f2.clear();> >> > return At;> > }> >> > I did it like that, bcuz I realized that using 'assign' does it make a bit > > faster,though a lot of resize is needed. I use Eclipse, so is it possible > > to adapt the Debugging stuff there? Or does it need to be in a > > makefile...yeah, I know, I dont know the basic stuff :). I read about the > > library binding, but I actually dont need things like svd, lu..all I need > > is prod,solve,element_div and the methods above. So not to freaky things, > > so I probabaly dont need the bindings, right?> >> > Anyways, I thank you all very much..I never got answers so fast in a > > forum..I appreciate it.> >> >> >> >> >> > _________________________________________________________________> > Discover the new Windows Vista> > http://search.msn.com/results.aspx?q=windows+vista&mkt=en-US&form=QBRE> > _______________________________________________> > Unsubscribe & other changes: > > http://lists.boost.org/mailman/listinfo.cgi/boost> > > > > > _______________________________________________> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
_________________________________________________________________
Connect to the next generation of MSN Messenger
http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk