Executing Gummiworms The trials and tribulations of a grumpy curmudgeonly old git

13Aug/122

COBOL on the Raspberry Pi

I have a bit of a soft spot for COBOL. I was taught & used the Ryan-McFarland version on Tandy Model III & IVs at college & one of the first programs I ever got paid to write although originally written in compiled BASIC was quickly rewritten in COBOL, for those that are interested it was a complete accounting & payroll suite including interfacing to a Hugan-Alpha till (cash register) for stock control for a Camping, Caravaning & Outdoor Leisure activities store. I was actually quite proud of it and from what I heard it was still in use until fairly recently nearly 30years after I originally wrote it although I haven't been involved with maintaining it for nearly 15 years. Anyway because I do have this soft spot for COBOL (and I still program in it on occasion, which is why I am always grumpy :) )  when I got my Raspberry Pi I built OpenCOBOL for it, actually i built it before I got my Raspberry Pi as I originally built it last September using my Raspberry Pi development VM but all i did with it was run the tests to check that it built, ran correctly & produced working binaries & modules. However, a few weeks ago Heirloom Computing Inc released a version of their Elastic COBOL compiler for the Raspberry Pi for free, the press release is available to read here, so I decided to rebuild OpenCOBOL actually on my Raspberry Pi & compare the two as they have different methods of producing runnable code, OpenCOBOL produces C code that can then be compiled to a standalone binary or a callable module, Elastic COBOL produces Java code that is then run on JVM, Elastic COBOL has builtin GUI functions, OpenCOBOL has no GUI out of the box other than normal COBOL screen handling but it does have the ability to produce GUI applications using 3rd party libraries such as GTK or TUI or Qt or ... and OpenCOBOL is opensource & Elastic COBOL is free to use although the compiler has a "phone home" function that requires you to have your Raspberry Pi attached to the internet via the Ethernet connection at least once a week , it must be Ethernet, Wifi won't work.

To build & install OpenCOBOL on the Raspberry Pi

1. Downlaod the source tarball from http://sourceforge.net/projects/open-cobol/

2. Install (if not already installed) the headers & shared lib for ncurses & berkeleydb, berkeleydb is sort of optional if you haveanother ISAM library installed but the 3 current ISAM choices don't necessarily work on ARM devices or if they do are a bit flakey so it's best to just go with berkeleydb > 4.1. on raspbian

sudo apt-get install libncurses5 libncurses5-dev libdbx.x libdbx.x

where x.x is the version of berkeleydb that is available that is > 4.1 (raspbian has several versions all are ok to use)

3. untar the source tarball, cd to the directory that it untared to (open-cobol1.1 probably) and

./configure ; make ; make check

and if all the tests passed (it'll take about 25minutes with gcc 4.6 & for some weird reason that I can't fathom about 30minutes with gcc 4.7)

 sudo make install

to install Elastic COBOL on the Raspberry Pi

1. Register on the Elastic COBOL portal at https://www.elasticcobol.com/index.php/raspberry-pi/ and then once you you have registered and logged in follow the setup instructions that Heirloom Computing have supplied.

2. I did have one slight problem when I was sent the elasticcobol.properties file that is needed to get Elastic COBOL to. Thunderbird "hid" the attached file and I had to manually cut & paste it out of the message source (Ctrl+U) and run it through uudecode manually.

 

Now you should have both Elastic COBOL & OpenCOBOL installed and usable, check that they both work. I used the ElasticCOBOL supplied hello world sample program.

ukscone@welham ~/cobapps $ cat hello.cbl
 *
 * HELLO-WORLD
 *
 * (C) Copyright Heirloom Computing 2011. All Rights Reserved.
 *
 * This file and associated files are copyrighted information
 * of Heirloom Computing. Permission is granted for usage in
 * conjunction with the Elastic COBOL product.
 *
 * This is an application meant to run using SYSOUT,
 * that is, a DOS Box under Windows or the console under Unix.
 *
 * This file also shows that the PROGRAM-ID is the important
 * factor in determing the name of the Java file. (As each
 * Java class needs its own file, and a single COBOL file
 * can have multiple COBOL programs and thus multiple Java
 * classes, you can see why the source filename was not used.)
 * Java names cannot have hyphens such as our PROGRAM-ID here
 * does, so underscores replace it, becoming "hello_world".
 *
 * This program's only purpose is to print upon sysout, and
 * as browsers do not normally have a sysout, do not run this in
 * a browser.
 *
 * To get this program to display in a browser, change
 * the SYSOUT to CONSOLE, or remove the UPON SYSOUT entirely,
 * and it will print upon a graphical console.
IDENTIFICATION DIVISION.
 PROGRAM-ID. HELLO.
ENVIRONMENT DIVISION.
DATA DIVISION.
 WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
 MAIN-PARAGRAPH.
 DISPLAY "Hello World from Raspberry Pi!" UPON SYSOUT.

As you can see below ElasticCOBOL is a bit slower because of the overhead of having to start the JVM but that really isn't that much of a concern as it's a small "fixed" amount of time that doesn't actually affect the speed of execution.

ukscone@welham ~/cobapps $ cobc -m hello.cbl
 ukscone@welham ~/cobapps $ time cobcrun hello
 Hello World from Raspberry Pi!
real 0m0.029s
 user 0m0.010s
 sys 0m0.010s
 ukscone@welham ~/cobapps $ ecc hello.cbl
 Elastic COBOL V12.7.20 Copyright (C) 2010-2012 Heirloom Computing
LOC: 40 (0 variables in 0 records)
 Warnings: 0
 Errors: 0
 Result: Compilation SUCCESSFUL
 Building: Class files
 ukscone@welham ~/cobapps $ time ecr hello
 Hello World from Raspberry Pi!
real 0m4.144s
 user 0m3.370s
 sys 0m0.260s
 ukscone@welham ~/cobapps $

A slightly more complicated program is hanoi.cob

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. hanoi.
000300 AUTHOR. Amit Singh <http://hanoi.kernelthread.com>.
000400
000500 ENVIRONMENT DIVISION.
000600
000700 CONFIGURATION SECTION.
000800 SOURCE-COMPUTER. ALMOST-PORTABLE.
000900 OBJECT-COMPUTER. ALMOST-PORTABLE.
001000
001100 DATA DIVISION.
001200
001300 WORKING-STORAGE SECTION.
001400
001500 01 STACK-SPACE.
001600 02 ESP PIC S9(3) COMP.
001700 02 STACK-FRAME OCCURS 1024.
001800 03 S-N PIC 9(1).
001900 03 S-FROM PIC X(1).
002000 03 S-USING PIC X(1).
002100 03 S-TO PIC X(1).
002200 03 S-PROC PIC 9(1).
002300
002400 01 CURRENT-FRAME.
002500 02 CN PIC 9(1) VALUE 3.
002600 02 CFROM PIC X(1) VALUE "1".
002700 02 CUSING PIC X(1) VALUE "2".
002800 02 CTO PIC X(1) VALUE "3".
002900 02 CPROC PIC 9(1) VALUE 0.
003000
003100 01 TMP-FRAME.
003200 02 TN PIC 9(1) VALUE 3.
003300 02 TFROM PIC X(1) VALUE "1".
003400 02 TUSING PIC X(1) VALUE "2".
003500 02 TTO PIC X(1) VALUE "3".
003600 02 TPROC PIC 9(1) VALUE 0.
003700
003800 PROCEDURE DIVISION.
003900 BEGIN-PROGRAM.
003910 PERFORM GET-DISKS
004000 MOVE 1 TO ESP
004100 MOVE CURRENT-FRAME TO STACK-FRAME (ESP)
004150 PERFORM DO-HANOI
004200 UNTIL ESP = ZERO
004300 .
004500 STOP RUN
004600 .
004700
004800 DO-HANOI.
004900 MOVE STACK-FRAME (ESP) TO CURRENT-FRAME
005000 SUBTRACT 1 FROM ESP
005100 IF CPROC = 0
005200 IF CN = 1
005300 PERFORM MOVE-DISK
005400 ELSE
005500 MOVE CN TO TN
005600 MOVE CFROM TO TFROM
005700 MOVE CUSING TO TUSING
005800 MOVE CTO TO TTO
005900 MOVE 1 TO TPROC
006000 ADD 1 TO ESP
006100 MOVE TMP-FRAME TO STACK-FRAME (ESP)
006200 MOVE CN TO TN
006300 SUBTRACT 1 FROM TN
006400 MOVE CFROM TO TFROM
006500 MOVE CTO TO TUSING
006600 MOVE CUSING TO TTO
006700 MOVE 0 TO TPROC
006800 ADD 1 TO ESP
006900 MOVE TMP-FRAME TO STACK-FRAME (ESP)
006950 END-IF
007000 ELSE
007100 PERFORM MOVE-DISK
007200 MOVE 0 TO TPROC
007300 MOVE CTO TO TTO
007400 MOVE CFROM TO TUSING
007500 MOVE CUSING TO TFROM
007600 MOVE CN TO TN
007700 SUBTRACT 1 FROM TN
007800 ADD 1 TO ESP
007900 MOVE TMP-FRAME TO STACK-FRAME (ESP)
008000 END-IF
008100 .
008200
008300 MOVE-DISK.
008400 DISPLAY CFROM
008500 "--> "
008600 CTO
008700 .
008800
008900 GET-DISKS.
009000 DISPLAY "How many disks to solve for? " NO ADVANCING
009100 ACCEPT CN.
009200 IF CN < 1 OR CN > 9
009300 DISPLAY "Invalid number of disks (1 <= N <= 9)."
009400 EXIT PROGRAM
009500 END-IF
009600 .
009700 .
ukscone@welham ~/cobapps $ cobc hanoi.cob
ukscone@welham ~/cobapps $ cobcrun hanoi
How many disks to solve for? 5
1--> 3
1--> 2
3--> 2
1--> 3
2--> 1
2--> 3
1--> 3
1--> 2
3--> 2
3--> 1
2--> 1
3--> 2
1--> 3
1--> 2
3--> 2
1--> 3
2--> 1
2--> 3
1--> 3
2--> 1
3--> 2
3--> 1
2--> 1
2--> 3
1--> 3
1--> 2
3--> 2
1--> 3
2--> 1
2--> 3
1--> 3

[i couldn't be bothered to edit the source so that Elastic COBOL used the stdout so below is a jpeg of it's output. it pretty much took the same amount of time to run (after subtracting the java overhead)

 

Now that I know that both OpenCOBOL & ElasticCOBOL work pretty well on the Raspberry Pi I decided that before messing around with ElasticCOBOL any more e.g. looking into which dialect of COBOL it uses (it's cobol85 with a few additions for the gui and some inline java) i'd run a completely biased benchmark. I knew before I even ran it that ElasticCOBOL would be slooooow as java on the Raspberry Pi is slow & as far as I know doesn't use the floating point hardware. I am just interested to see if it will run out of the box or with minimal changes & it required only changing the name of a variable from Time-Out to Tyme-Out as ElasticCOBOL has TIME-OUT as a reserved word and the in/out filenames.

You can find the benchmark code & datafiles at http://speleotrove.com/decimal/telco.html.

I used the COBOL version with http://speleotrove.com/decimal/expon180-1e6.zip datafile.

With an non-overclocked Raspberry Pi using OpenCOBOL1.1 compiled with gcc 4.6 the benchmark took from

Start-Time:23:39:39.08 to End-Time:23:41:26.26 =1m47ish

and ElasticCOBOL took from  Start-Time:22:20:49.58   to End-Time:23:16:04.66   = 56minutesish :)

 

As I said this was a completely biased benchmark as I am an OpenCOBOL fanboy and knew it would win hands down but I am still quite impressed with ElasticCOBOL even if it is using java and hits my "irrational loathing of java" prejudice but it's gui stuff is great and very responsive and i'll probably spend more time playing around with it but I definitely won't be processing a million entry data file with it :)

Share
Comments (2) Trackbacks (2)
  1. We won’t see much improvement on the performance side until Raspi gets a JVM with a JIT (right now, it’s purely interpreted).

    BTW, if you want to map console output to sysout/syserr (without changing your source), you can compile your program like this:

    $ ecc -run:system myprog

    • thanks i’ll give that a go. although i have been a bit down on elastic cobol i actually do like it and it definitely has it’s place in my toolbox. the gui stuff is very nice and pretty responsive. i just have a completely prejudiced bias against things that use/require JVM that one day i’m sure someone will beat out of me with a clue by four :)


Leave a comment