Test template
Sunday, 24 August 2014
Parallel fib In Go
package main import( "fmt" "time" "runtime" ) func fib(n uint64) uint64 { if n <= 2 { return 1 } return fib(n-1) + fib(n-2) } func pfib(n uint64) uint64 { if n <= 2 { // terminate recursion return 1 } // create a channel for subtask results res := make(chan uint64, 2) // fork 2 subtasks, they will send results to the res channel go func() { res <- fib(n - 1) }() go func() { res <- fib(n - 2) }() return <-res + <-res } func main(){ runtime.GOMAXPROCS(2) t0 := time.Now() fmt.Printf(" %d\n", pfib(48) ) t1 := time.Now() fmt.Printf("time %v to run.\n", t1.Sub(t0)) }
Parallel fib in Lisp
Parallel Lisp
see http://lparallel.org/defpun
lparallel is available in quicklisp; ccl is a good lisp in windows.
A recursive fib is an example people often use to illustrate parallel processing (cilk for example)
This parallel fib is significantly faster than a plain fib; but nothing like as fast as cilk (parallel c)
Sunday, 7 February 2010
MSXML - enable xpath query
To enable MSXML for use with XPATH queries you have to set the name spaces and also the language property to XPath like so:-
myDoc := CreateComObject(CLASS_msDOMDocument) AS IXMLDOMDocument2;
myDoc.setProperty('SelectionNamespaces', Format('xmlns:my="%s"', [NSMY]));
myDoc.setProperty('SelectionLanguage','XPath'); // enable advanced query
myDoc := CreateComObject(CLASS_msDOMDocument) AS IXMLDOMDocument2;
myDoc.setProperty('SelectionNamespaces', Format('xmlns:my="%s"', [NSMY]));
myDoc.setProperty('SelectionLanguage','XPath'); // enable advanced query
Sunday, 10 January 2010
Delphi: Read XML document from an embedded resource.
If your application wants to work with XML data; sometimes it is useful to shove that data into the executable; so it can start with a 'blank form' for example.
You can pack XML into a resource in Delphi and read it using a TResourceStream like this:-
procedure TForm1.loadInternally(var myDoc: msDOMDocument);
const
NSMY = 'http://schemas/mynamespace/blah/blah';
var
resource: TResourceStream;
xmlString: string;
l: integer;
sstream: TStringStream;
begin
myDoc := CreateComObject(CLASS_msDOMDocument) AS IXMLDOMDocument2;
myDoc.setProperty('SelectionNamespaces', Format('xmlns:my="%s"', [NSMY]));
// get embedded data
resource :=TResourceStream.CreateFromID(HInstance, 500, RT_RCDATA);
sstream :=TStringStream.Create;
resource.SaveToStream( sstream );
xmlString:= sstream.DataString;
// and load..
if not myDoc.loadXML(xmlString) then
showmessage('Internal Document load failed');
// release memory.
resource.Free;
sstream.Free;
end;
Sunday, 18 January 2009
Read an XML document with namespaces and import the data by path using DELPHI.
const
NSMY = 'http://my.namspace.com/namespace';
PATH = '/my:myFields/my:myFields_1/my:FieldName_1';
var
text: string;
Doc: DOMDocument;
node:IXMLDOMNode;
begin
Doc:=CreateComObject(CLASS_DOMDocument) AS IXMLDOMDocument2;
Doc.load('c:\testXML\testForm.xml');
Doc.setProperty('SelectionNamespaces', Format('xmlns:my="%s"', [NSMY]));
node := Doc.selectSingleNode(PATH);
Text:=node.Text;
end;
To access a node in the 'my:' namespace by xpath use the units MSXML2_TLB and ComObj.
You can create MSXML2_TLB by importing the type library for MSXMLv3.0.
const
NSMY = 'http://my.namspace.com/namespace';
PATH = '/my:myFields/my:myFields_1/my:FieldName_1';
var
text: string;
Doc: DOMDocument;
node:IXMLDOMNode;
begin
Doc:=CreateComObject(CLASS_DOMDocument) AS IXMLDOMDocument2;
Doc.load('c:\testXML\testForm.xml');
Doc.setProperty('SelectionNamespaces', Format('xmlns:my="%s"', [NSMY]));
node := Doc.selectSingleNode(PATH);
Text:=node.Text;
end;
To access a node in the 'my:' namespace by xpath use the units MSXML2_TLB and ComObj.
You can create MSXML2_TLB by importing the type library for MSXMLv3.0.
Wednesday, 12 December 2007
Detecting the mode of the ARM processor from Forth
Detecting the ARM processor mode from Forth.
Modern ARM processors have no 26Bit mode, they do support an emulator
To detect the mode you are running in.
code 32bit?
stmfd sp !, { tos }
teq r0, r0
teq pc, pc
mvn eq tos, # 0
mov ne tos, # 0
next c;
Returns true if 32bit or false otherwise.
This example is from WimpForth for RISCOS (a version that runs on StrongARM) can be found at http://www.leginda.com
Subscribe to:
Posts (Atom)