473,383 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 2355
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
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...
12
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...
4
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...
21
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...
10
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...
10
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
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...
4
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...
12
by: nooneinparticular314159 | last post by:
Hello. If I declare the following: template<int a, int b, int SomeArray> class DoSomething{ public: .. .. ..
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.