Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Code Samples & Tips > Additional Libraries
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Additional Libraries Users contributed libraries.
This sub-forum is only available to licensed users.

MathRecompiler performance enhancer

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-13-2009, 04:32 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default MathRecompiler performance enhancer

Although not a library I think that this thread is probably the correct home for this utility.

This is the culmination of my efforts to get high performance maths under Basic4ppc. This utility will give optimised compiled Basic4ppc applications that require it almost the same level of numeric performance that C# and VB.NET applications enjoy, at least for Double values. It is based on the recompilation technology of my DebugRecompiler program. It will recompile individually specified Subs in an application to perform all numeric operations as .NET Double types but such Subs will have to conform to a set of constraints if the recompilation is to be successful.

The archive contains the MathRecompiler utility, help and an admittedly rather artificial demo app that shows an approximately 25 fold increase in performance on my Vista desktop and similar on my iPAQ 214 when recompiled.

I may well not have covered all the recompilation scenarios so if you find some code that won't recompile despite conforming to the stated constraints then please post it and if possible I will modify the utility accordingly.

Hopefully, at some time in the (not too distant) future further enhancements to Basic4ppc itself will make this utility redundant but until that time this will make some applications feasible that would take too long to run otherwise.

EDIT:- Quick update to version 1.3. See post #9 for details.

EDIT:- Updated to version 1.4 See post #12 for details. I didn't deliberately design it in but it seems that version 1.4 works with Single, Int32 and Int64 arrays as well as Doubles which could be useful to save memory with large data sets.

EDIT:- This library is now obsolete with the release of Basic4ppc version 6.90.
Attached Files
File Type: zip MathRecompiler1.4.zip (35.2 KB, 75 views)
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 05-29-2010 at 04:10 PM.
Reply With Quote
  #2 (permalink)  
Old 10-14-2009, 10:20 AM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Hi Andrew,

I wanted to try the MathRecompiler with your demo program, but have some trouble:
1) My Basic4PPC is in a different folder than the default one. I added a MathRecompiler.ini file with:
C:\Program Files\Anywhere Software\Basic4ppc Desktop_V6_80 , the directory where the Basic4ppc Desktop.exe is located.
And get the error message in the 1st picture.
I tried also this MathRecompiler.ini file:
C:\Program Files\Anywhere Software\Basic4ppc Desktop_V6_80\Tzor
same result.

2) I copied the whole B4PPC folder with the default directory name. Loaded the B4ppc IDE from there and compiled (optimized Windows EXE). But I get the error message in the 3rd image. The 4th image shows the message whit pause compilation.

What am I doing wrong ?

Another question: The help file says the other Subs should not be called from within a Double subroutine. In the Dynamic Simulation program where I am interested to add the MathRecompilation I call some subroutines but with no parameters tramsmitted and no return value expected. Could such cases be added in the Recompiler or do I need to copy all the subroutines into one, this would become a huge one because several routines are called several times.

Best regards and thank you for this improvement.

Best regards.
Attached Images
File Type: jpg CompilerError0.jpg (21.6 KB, 22 views)
File Type: jpg Recompiler.jpg (19.5 KB, 18 views)
File Type: jpg CompilerError.jpg (12.9 KB, 12 views)
__________________
Klaus
Switzerland
Reply With Quote
  #3 (permalink)  
Old 10-14-2009, 10:54 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

1) It's MathRecompiler.inf (information) not MathRecompiler.ini.

2) The Tzor folder and its contents need to exist under the Basic4ppc installation folder - I suspect you haven't copied them.

The next version will support Msgbox, without a return value, as it might help in debugging and I am thinking about sub-routines. To keep the performance up, which is the whole reason for this, it will probably only be possible to call recompiled sub-routines with no return values. To return results Double globals could be used. It is likely that such sub-routines will need to be annotated "Subname_AsDoubleSub" so the recompiler can optimise the parameter passing. Such Subs could call each other but not an "_AsDoubles" Sub which would be the top level interface to normal Basic4ppc code.

EDIT:- I'm also likely to change _"AsDoubles" to the singular "_AsDouble" 'cos I don't like the plural now I've used it!

FURTHER EDIT:- Due to a side effect that I overlooked I've just realised (and tested) that subroutines without parameters or return values do in fact work!
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.

Last edited by agraham : 10-14-2009 at 11:38 AM.
Reply With Quote
  #4 (permalink)  
Old 10-14-2009, 12:23 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Hi Andrew,

Thank's for the answer.
Sorry for the mistake between .ini and .inf.

With the correct MathRecompiler.inf file the Recompiler finds the new directory.
But I still get the same error as shown in the 4th image in my previous post.
The 4 *.cs files reported there are in the Tzor folder as shown in the image below, they were also copied when I copied the whole B4PPC folder to a folder with the default name.

Having "Subname_AsDoubleSub" subs would really be fine !
The routines I was speeking about manipulate Global Double variables.

Best regard and thank's for the help.
__________________
Klaus
Switzerland
Reply With Quote
  #5 (permalink)  
Old 10-14-2009, 12:44 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Open a command window in your project directory and type

mathrecompiler /p

You will get a message box showing two paths. The top one should be the path to the Tzor folder - check that it is what you expect.


When you get it running note that subroutines calls do work to either _AsDoubles or normal Subs as long as they take no parameters and any return values are not used. I am unlikely to be able to improve on this for technical reasons to do with .NET delegates.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #6 (permalink)  
Old 10-14-2009, 12:58 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Hi Andrew,

Attached the PathInfo message.
The B4PPC path is the correct one.

Best regards.
__________________
Klaus
Switzerland
Reply With Quote
  #7 (permalink)  
Old 10-14-2009, 01:16 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

The recompiler writes a batch ffile like this and then deletes it when it is finished.
Code:
@echo off
cd 
"C:\Program Files\Anywhere Software\Basic4ppc Desktop\Tzor"
@echo on
C:\Windows\Microsoft.NET\Framework\v2
.0.50727\csc.exe /o /noconfig /nostdlib /nologo /target:winexe /out:"C:\Users\Andy\AppData\Roaming\Anywhere Software\Basic4ppc\Tzor\1.exe" /define:DEVICE @"C:\Users\Andy\AppData\Roaming\Anywhere Software\Basic4ppc\Tzor\1.rsp" /define:AUTOSCALE /warn:1
@echo off
@echo.
@echo.
Del 
"C:\Users\Andy\Documents\Basic4PPC\MathRecompiler\Going"
Note that the first line is a change directory to work from the Tzor folder where the cs files are. I've just noticed that in your command window the present directory is not the Tzor folder, it is your project folder on D: I think this is the problem, you can't "cd" across drives. Try it from a folder on your C: drive
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #8 (permalink)  
Old 10-14-2009, 04:20 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Thank's Andrew.
Now after copying the folder to the C dirve it works fine.
I think this information would be useful in the help file.

Just a typo in the help file:
'This help file documents version 1.2 of the DebugRecompiler utility.'
should be
'This help file documents version 1.2 of the MathRecompiler utility.'

Best regards.
__________________
Klaus
Switzerland
Reply With Quote
  #9 (permalink)  
Old 10-14-2009, 04:30 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 5,953
Awards Showcase
Innovator medal Beta Tester Forum Contributer 
Total Awards: 3
Default

Version 1.3 now posted.

MsgBox statements may now be used in a recompiled Sub in case it is useful for debugging.

_AsDouble is now the preferred indicator suffix for a Sub to be recompiled but _AsDoubles is still accepted.

Help is changed to document MsgBox and give a description of the constraints of calling other Subs from a recompiled Sub.

The project folder may now be located on a drive other than the one on which Basic4ppc is installed.
__________________
Sorry, but I don't answer questions by PM or email.
Please post your queries in the forum.
Reply With Quote
  #10 (permalink)  
Old 10-14-2009, 09:15 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 3,827
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Hi Andrew,

I tried version 1.3, it works well also from disc d:
I ran your demo program recompiled with version 1.2 and also with version 1.3.
It seems that there is a big difference in the execution speed ?
Version 1.2 32 times speed increase.
Version 1.3 8 times speed increase.

Enclosed both exe files.

EDIT: The two source codes of the demo program are different between version 1.2 and 1.3. The call of the DoMathsSub routine from DoMaths_AsDouble instead of calculating directly in this routine makes the differenche.

Best regards.
__________________
Klaus
Switzerland

Last edited by klaus : 10-15-2009 at 08:06 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Navigation Performance Saj Questions (Windows Mobile) 15 07-18-2009 12:08 PM
Performance vs Memory RandomCoder Questions (Windows Mobile) 4 02-10-2008 05:03 PM
Performance on Bitmap? Roadrunner Questions (Windows Mobile) 9 12-09-2007 03:19 PM


All times are GMT. The time now is 04:48 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0