Any Fortran coder ?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

brianr
Posts: 536
Joined: Thu Mar 09, 2006 3:01 pm

Re: Any Fortran coder ?

Post by brianr »

Dann Corbit wrote: Fri Nov 16, 2018 2:05 am
brianr wrote: Fri Nov 16, 2018 12:31 am
hgm wrote: Thu Nov 15, 2018 9:31 pm I think I never got beyond Fortran 60 (or something like that), before I switched to other programming languages. Fortran 77 already appeared 'after my time'... Problem used to be that you couldn't do recursion; I don't know if later Fortrans fixed that.
Tinker's great grandfather started in Fortran. I did recursion just fine with an explicit stack. It was pretty straightforward, as I recall.
Recursion has been available since Fortran90:

http://fortranwiki.org/fortran/show/recursion
My memory isn't what it used to be, but I don't think Fortran90 was available in 1975, when I "rolled my own" recursion. At that time on a PDP-11/60 with some bits of assembler in key places, Tinker's predecessor could hit around 4 plys from the starting position (much deeper in endgames, of course). The first 1971 version ran from punch cards on an IBM-1130 (3.6 usec, that's microseconds for simple add register ops) struggled to get to 2 ply. Move times were not in seconds, but minutes. Design was constrained by 8K bytes of RAM to avoid extremely costly disk swapping. If only I'd seen GnuChess' elegant nextdir nextpos movegen sooner...Magic bitmaps would have been science fiction. At that point, the evaluation was almost an after thought for me just trying to cobble together something that could reliably generate and make a couple of moves. Tinker became dormant until about 1996 with the appearance of Deep Blue, and the first sort-of C version played on ICC in January 2000 (huge thanks to Bob Hyatt for Crafty, Tim Mann for Winboard, GnuChess, and many others). It ran on AMD's Opteron, the first practical broad market 64 bit CPU (Itanium was useless for chess).
User avatar
Ajedrecista
Posts: 1968
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: Any Fortran coder?

Post by Ajedrecista »

Hello:
ker2x wrote: Thu Nov 15, 2018 7:52 pm Friendly greetings !

I'm writing a chess engine (my 1st engine ! yay !), using fortran.

I'm not sure which board representation would be a best fit for this language.

Techincally, fortran doesn't have uint64_t (only signed) but it should be a very major problem if the bitfield is only used for bit manipulation, and not math.
Another option could be a logical matrix (a 2d array of boolean) but it may kind of defeat the effectiveness of a bitboard.
Or it could be any other board representation, probably.

i don't know. Any idea ?

The source code is here https://github.com/ker2x/fortiche but it doesn't do anything at all, for now.
Dann Corbit wrote:There is a guy here who wrote "Six_Fortran_95_tools" and he is probably much more helpful for Fortran stuff.
Thanks for think in me, Dann, but I am not a programmer. I barely do some math and that is all. These tools are mainly statistical, like LOS (Likelihood of Superiority) and error bars calculator, probabilities in a trinomial distributions (it could be somewhat useful in short matches like the current WCC Carlsen - Caruana), a rating tool for Round Robin tournaments that outputs very similar results when compared to EloSTAT, a Round Robin pairings generator... so really nothing about a chess engine.

Lately I worked in a LLR (Log Likelihood Ratio) calculator and SPRT simulators, that I use in SF Framework sometimes. Again, nothing like a chess engine, only math, numbers, statistics and so on about chess.

That being said, I stay tuned for Laurent's progress because I would like to write a chess and/or checkers engine in Fortran but I lack time and programming knowledge and skills, so basically I lack everything. Good luck with your project!

Regards from Spain.

Ajedrecista.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Any Fortran coder ?

Post by bob »

Recursion has worked for a long time now. One thing to avoid is a 2d array, use a 1d vector instead. Otherwise every array access ends up with an integer multiply buried in the middle of the address calculation. Otherwise it will work fine. The language is a bit of a mismatch for chess but I used it for many years (Cray Blitz) with good results.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Any Fortran coder ?

Post by Evert »

ker2x wrote: Fri Nov 16, 2018 8:47 am i have no problem writing code to handle the UCI interface for now, in fact the only thing i wrote in my engine for now is the UCI parser.
Which lead me to my current problem.
Writing a UCI parser in Fortran isn’t the main issue (although I never found Fortran string manipulation particularly convenient to use; it’s not what the language was designed for anyway), getting unbuffered I/O from the program is the annoying part.
In principle you can flush the file, but I seem to recall that not being reliable in all cases due to quirks of buffering done in Fortran itself interfering with buffering done by the OS. Could have been a faulty compiler though (and limited knowledge of Fortran when I tried to do that).
the read operation is blocking, so i need a thread just for this (i'll use the main thread for all the I/O).
But i can't find a way to the multithreading/multiprocessing working on both windows and linux/bsd/mac.
Can’t you use INQUIRE on unit 5 to find out if there is input available?
Or, hou know, call a C function from Fortran.
i'm also considering openMPI but it's a pain to make it works on both platform and certainly not user friendly. And i don't think it would be allowed to enter chess competition (but it could run on a 200.000 cpu cluster however, hehehe, not that i have access to any massive cluster anyway).
OpenMP should be ok, although it’s not really intended for launching a dedicated I/O thread. It’s probably the easiest way to get multithreading in Fortran. Requires compiler support though.
Werewolf
Posts: 1796
Joined: Thu Sep 18, 2008 10:24 pm

Re: Any Fortran coder ?

Post by Werewolf »

hgm wrote: Thu Nov 15, 2018 9:31 pm I think I never got beyond Fortran 60 (or something like that), before I switched to other programming languages. Fortran 77 already appeared 'after my time'... Problem used to be that you couldn't do recursion; I don't know if later Fortrans fixed that.
I used ForTran 77 for a while....old times.
User avatar
emadsen
Posts: 434
Joined: Thu Apr 26, 2012 1:51 am
Location: Oak Park, IL, USA
Full name: Erik Madsen

Re: Any Fortran coder ?

Post by emadsen »

smcracraft wrote: Fri Nov 16, 2018 3:33 am If you work in the profession as a developer or devops or other person who codes partially or wholly for a living, I suggest you pick another language.

C and C++ are the standard languages I am aware of that most of the modern chess programs I have seen have been written in.
Our community is enriched by hobbyists who write chess software in their language of choice. I certainly feel that way as an author of a chess engine written in a non-standard (not C or C++) language.

Not every project has as its goal the dethroning of Stockfish. So I say if you want to write a chess engine in Fortran, go for it. One of the benefits of welcoming hobbyists using eclectic languages is it gives beginning programmers more opportunity to understand chess algorithms. The beginner can read source code in the language they're most familiar with, then move on to more optimal languages once they've mastered the concepts. I feel it's important to grow our community outward, through diversity of language and technique (A/B, Monte Carlo, NN), and not just upward by further optimizing the already highly-optimized C++ king.
My C# chess engine: https://www.madchess.net
ker2x
Posts: 17
Joined: Sun Nov 11, 2018 1:28 pm
Full name: Laurent Laborde

Re: Any Fortran coder ?

Post by ker2x »

emadsen wrote: Sun Nov 18, 2018 12:45 am
smcracraft wrote: Fri Nov 16, 2018 3:33 am If you work in the profession as a developer or devops or other person who codes partially or wholly for a living, I suggest you pick another language.

C and C++ are the standard languages I am aware of that most of the modern chess programs I have seen have been written in.
Our community is enriched by hobbyists who write chess software in their language of choice. I certainly feel that way as an author of a chess engine written in a non-standard (not C or C++) language.

Not every project has as its goal the dethroning of Stockfish. So I say if you want to write a chess engine in Fortran, go for it. One of the benefits of welcoming hobbyists using eclectic languages is it gives beginning programmers more opportunity to understand chess algorithms. The beginner can read source code in the language they're most familiar with, then move on to more optimal languages once they've mastered the concepts. I feel it's important to grow our community outward, through diversity of language and technique (A/B, Monte Carlo, NN), and not just upward by further optimizing the already highly-optimized C++ king.
yeah i started the project in c++ then switched to fortran because c++ wasn't fun enough. :roll:
It's my 1st engine, my goal is to enter in competitions and lose without crashing :mrgreen: