## Any Fortran coder ?

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
ker2x
Posts: 17
Joined: Sun Nov 11, 2018 12:28 pm
Full name: Laurent Laborde

### Any Fortran coder ?

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.

maksimKorzh
Posts: 81
Joined: Sat Sep 08, 2018 3:37 pm
Location: Ukraine
Full name: Maksim Korzh
Contact:

### Re: Any Fortran coder ?

Congratulations with your first attempt! Just curious - why Fortran?

Dann Corbit
Posts: 10243
Joined: Wed Mar 08, 2006 7:57 pm
Location: Redmond, WA USA
Contact:

### Re: Any Fortran coder ?

I did Fortran in the 70's and 80's. All the sample programs and stuff you can find will be quite old and out of date as far as the latest techniques go.
There is a guy here who wrote "Six_Fortran_95_tools" and he is probably much more helpful for Fortran stuff.
Robert Hyatt, who wrote Crafty certainly knows a lot about Fortran.

Here is a Fortran chess program:
https://github.com/arbolis/fortranchess ... /chess.f90

I added the sample fortran77 program from f77bench (kind of old) as an attachment.

The Fortran source for Cray Blitz is still around. I have several versions of it.

I had a Fortran95 chess program at one time, but I don't remember where I put it.

I am doing a disk grep for it now, and I will see if I can find it.

Since integers are signed in Fortran, bitwise operations would be a problem, but some Fortran compilers allow inline assembly.
You could also do an interface to C++ for that bit.

If you want it all in portable Fortran code, then one of the mailbox/array techniques is probably best.

I found a project that looks interesting called sigma chess which has some of the code in Fortran:

Code: Select all

 Directory of F:\project\dcorbit\sigma-chess-read-only\Application\Source\Chess Engine

2013-08-29  05:27 PM             4,677 Engine.f
1 File(s)          4,677 bytes

2013-08-29  05:27 PM             2,092 Attack.f
2013-08-29  05:27 PM             2,216 Board.f
2013-08-29  05:27 PM             2,066 Move.f
3 File(s)          6,374 bytes

2013-08-29  05:27 PM             1,999 Evaluate.f
2013-08-29  05:27 PM             1,923 Mobility.f
2013-08-29  05:27 PM             1,969 PieceVal.f
3 File(s)          5,891 bytes

2013-08-29  05:27 PM             1,889 EndgameDB.f
2013-08-29  05:27 PM             2,070 HashCode.f
2013-08-29  05:27 PM             2,041 Time.f
3 File(s)          6,000 bytes

2013-08-29  05:27 PM             2,335 MoveGen.f
2013-08-29  05:27 PM             1,958 PerformMove.f
2 File(s)          4,293 bytes

2013-08-29  05:27 PM             1,896 MateSearch.f
2013-08-29  05:27 PM             2,200 Search.f
2013-08-29  05:27 PM             2,035 SearchMisc.f
2013-08-29  05:27 PM             1,924 Selection.f
2013-08-29  05:27 PM             1,886 Threats.f
2013-08-29  05:27 PM             2,022 TransTables.f
6 File(s)         11,963 bytes

Attachments
f77bench-chess.7z
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.

ker2x
Posts: 17
Joined: Sun Nov 11, 2018 12:28 pm
Full name: Laurent Laborde

### Re: Any Fortran coder ?

@maksimKorzh : thank you. i do it in fortran because i can and fortran is awesome. No real practical reason.

@dann : Thank you for the code and info, i'll take a look.

Btw, any idea how i can do multi-threading working on both windows and linux ?
I also considered multiprocessing + MPI but i don't see how i can make it works on both plateform again.

i'm using gfortran (and the simply fortran IDE). My main development plateform is windows (at home) but i'm a linux sysadmin, so... i want both and windows is a pain to deal with.

hgm
Posts: 23878
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

### Re: Any Fortran coder ?

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.

ker2x
Posts: 17
Joined: Sun Nov 11, 2018 12:28 pm
Full name: Laurent Laborde

### Re: Any Fortran coder ?

Fortran changed, you can still do old fashined fixed form fortran and stuff but you can also do freeform fortran, or Object Oriented Fortran

Modern compiler even have auto vectorization and auto parallelization, so loop can run on mutiple core without having to write a single line of additional code, i'm pretty sure it's inherited from cray fortran compiler.

Dann Corbit
Posts: 10243
Joined: Wed Mar 08, 2006 7:57 pm
Location: Redmond, WA USA
Contact:

### Re: Any Fortran coder ?

Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.

ker2x
Posts: 17
Joined: Sun Nov 11, 2018 12:28 pm
Full name: Laurent Laborde

### Re: Any Fortran coder ?

Yes, i know this one. but i don't want to do SIMD (well, i'll also do it but it's a different problem) so openmp, coarray, cuda, isn't a solution for this case (i already planned to use openmp for the computation part).

From this list only MPI could do the job and i don't know if i can use openmpi on both windows and linux without having to write tons of #ifdef windows/linux to make it portable.

ker2x
Posts: 17
Joined: Sun Nov 11, 2018 12:28 pm
Full name: Laurent Laborde

### Re: Any Fortran coder ?

and running open mpi app is a bit of a pain for the user

brianr
Posts: 360
Joined: Thu Mar 09, 2006 2:01 pm

### Re: Any Fortran coder ?

hgm wrote:
Thu Nov 15, 2018 8: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.