473,770 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using c++ template metaprogramming for high performance number crunching?

Ted
I have cross posted this to comp.lang.c++ and to sci.math.num-
analysis
in the belief that the topic is of interest to some in both groups.

I am building my toolkit, in support of my efforts in producing high
performance C++ code; code that is provably correct. The issue here
is orthogonal to the question of expression templates, which at
present seem to me to be relatively simple.
I began with the dimensional analysis as described in Abrahams and
Gurtovoy's book on template metaprogramming . From there, I developed
a template class hierarchy specific to simulation, that avoids
unnecessary copying of data during a simulation. All works fine, and
my simulation templates interact with the dimensional analysis
templates perfectly. The cost of using my templates is about the
same
as using the corresponding pods. At some point, if there is interest,
I can provide a little zip archive showing what I have done so far.
Just tell me how you want to receive it if you want to see some
trivially simple code.
Anyway, the problem I am wrestling with, so far unsuccessfully,
relates to the question of units of measurement, and especially how
to
avoid what ought to be unnecessary flops during the simulation.
Suppose I have a volume variable, with measurements in cubic meters,
and a density variable, expressed in ounces per cubic centimeter, and
a mass expressed in kilograms. Obviously contrived though this
example is, it is simple enough to illustrate what I need to do.
Obviously, templates adequate from the perspective of dimensional
analysis as described in Abrahams and Gurtovoy's book would allow me
to assign a quotient involving my mass and volume variables to the
density variable. Also obviously such an assignment, that ignores
units of measurement, is likely to be wrong in most cases.
What I want to do, ideally, is do a little extra metaprogramming to
provide for implicit conversions, both for situations where I have
one
length in miles and another in kilometers, and need to convert
between
the two, and for composite variables (e.g. converting between one
density expressed in ounces per cubic foot and another expressed in
kilograms per cubic meter), while correctly refusing to convert
obviously wrong attempts to convert, e.g., between a length in feet
and a mass in kilograms. And since all valid conversions are known a
priori, well before any attempt to compile code, one would want the
conversions to happen, ideally, at compile time, or at worst before
any simulation begins. If one thinks of the cost of iterating a
function a million times, and a particular conversion of a constant
used in the function involves several flops, the simulation wastes
millions of flops during the simulation if I fail to find a way to
automate the conversions so that it happens either at compile time or
at a minimum before the simulation begins.
I am not sure I can get what I want because most of the conversions I
am after require use of floating point numbers, and IIRC, they can't
be used as template arguments.
While one might argue that this is a waste of time, since one can
always do it manually, as one writes the code, failing to find a way
to automate it results in code that seems to me to be unnecessarily
rigid. Imagine that a simulation engine is developed using this,
embedded within an application that takes equations provided by the
user, parses them into a DLL that can be then loaded and used
(obviously such an application would need to be distributed with a
decent compiler able to produce a DLL, but that is another matter),
and concommitantly takes data from the user for use in parameterizing
his model. If the model involves energy, and the equations use it as
joules, while the only source of data the user has at hand expresses
values in calories, one imposes extra work, vulnerable to error, on
the user.
Is what I am after possible? If you think so, how would you do it?
My own efforts, along the lines of a traits template parameter,
representing units and operations on them, have not yet paid off. I
find myself floundering, in part on the problem of producing a
suitably flexible template class that provides correct implicit
conversions, while rejecting incorrect conversions. I am also having
trouble figuring out the correct partial specializations required. I
am now not convinced I am even on the right track for solving this
particular problem. It is frustrating to have achieved everything
else I wanted in my library intended to support high performance
simulation, and not to see clearly the solution to this problem. :-(
Any ideas?
Ted

Sep 21 '07 #1
1 2389
Ted wrote:
....
Is there a simple way to download your library, or do I have to do it
a file at a time?
You can :

a) Use subversion (TortoiseSVN)
b) Use a DAV client (WinXP has one).

Sep 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1715
by: YeeCN | last post by:
Hi, I need to write an application that requires HUGH volume of number crunching (tens of billions of calculations). Speed is the single most important factor for me. I am wondering is .NET (vb, c#) the right framework to develop the application so whether I should look somewhere else. Any help or suggestions is greatly appreciated.
12
2162
by: Dave | last post by:
Would people agree with the statement that to a large degree, using template metaprogramming techniques turns a C++ compiler into a C++ interpreter (but just for the metaprogrammed portions of the code)? It's not a perfect analogy, but it seems to be a reasonable statement...
4
3137
by: zzfreddybb | last post by:
We are using HP aCC compiler on a HP Itanium box ( 11.23) We are having some severe performance hits using exception handling ( try/catch ) scenarios. The online aCC documentation says: HP aC++ exception handling has no significant performance impact at compile-time or run-time. We have not found this to be the case at all.
21
2105
by: Protoman | last post by:
I've been looking at template metaprogramming. It seems really cool, make the compiler do most of the work. I have very simple program that uses TMP,it calculates the square of a number, but it doesn't seem to work. Here it is: #include <iostream> #include <cstdlib> using namespace std; template<int n>
10
1464
by: Frederick Gotham | last post by:
I'm trying to get a feel for template metaprogramming, and so I'm trying to write a compile-time "Raise number to positive integer" algorithm. So far, I have the following: template<class T, T base, unsigned exp> struct IntPosPow { static T const value = base * IntPosPow<T,base,exp-1>::value; };
10
2961
by: Ray | last post by:
I am reading Andrei Alexandrescu's book. The ideas presented there sound really good, but I wonder--is there really a lot of people using it? Or it's simply too esoteric for mortals? Cheers Ray
7
3544
by: Joe | last post by:
Hi, I found a concept named template metaprogramming that can be used in C+ + code at compile-time. I am a beginner at C++. But I am a programmer on the .NET platform. Do you know if template metaprogramming is supported in C# (.NET)? For reference I found it: http://en.wikipedia.org/wiki/Template_metaprogramming. Thanks to all.
4
1868
by: suman.nandan | last post by:
Hi C++ Experts ! I have a little weird requirement. I have a base class, say B and lots of classes D1 .. Dn publicly derived from it. Over the course of development the number of derived classes may increase. I want that before the execution of one of my particular code, I should have a list of pointers to all the derived classes, say std::list<B*ptrList; // contains 'n' elements which are pointers to D1 .. Dn.
12
3368
by: nooneinparticular314159 | last post by:
Hello. If I declare the following: template<int a, int b, int SomeArray> class DoSomething{ public: .. .. ..
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10057
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7415
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.