Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.

Machine Learning

Valued Contributor II


There is a machine learning in Fortran example at the location above. 


Screenshot 2022-05-14 154459.png

Screenshot 2022-05-14 154549.png


I have never liked make, nmake or cmake.  Just a personal thing stretching back to MS 3.03 Fortran.  

I loaded the code into a VS Project,  I get the errors in the first picture,  if I comment them out, the program runs although it is not likely to be correct.  

The cmake commands are shown in the 2nd picture for Fortran.  How can you have release and debug flags at the same time.  And in the properties page I could not find coarray single

I much prefer Fortran to Python.  

How do I fix the VS sln to match the cmake file?  






0 Kudos
23 Replies
Honored Contributor II

@JohnNichols ,

You may consider posting your inquiry also at the Fortran Discourse site:

The primary contact, Dr. Milan Curcic, of the neural net code in Fortran you've linked in the original post is not only an admin at the above Discourse site, he is a regular contributor there.  You may know he is also the author of a good book, "Modern Fortran: Building efficient parallel applications."

Dr. Curcic can provide guidance on how the code is setup to work with CMake, etc. that can then help adapt the build process using Visual Studio,


Black Belt

To John Nichols:

The package is intended to be built using Cmake and Gfortran in a Linux/Unix environment. On Windows, if you have WSL-1 or WSL-2, or Cygwin, along with Gfortran and Cmake, you can build and run the package.

I have Cygwin on my Windows PC. After extracting the Zip file with the Neural-Fortran package downloaded, I changed to the "neural-fortran-main" directory, and typed in the following commands



md build
cd build
cmake .. -DSERIAL=1



 The library was built and a number of EXEs were created in the bin subdirectory. I ran them, and all except mnist.exe ran to completion in a few seconds. However, mnist.exe needs space to create output files that occupy several hundreds of megabytes, and I aborted the run.

I tried to use Ifort instead of Gfortran, and quickly found that Cmake failed. Cmake could not even figure out how to call Ifort to compile a dummy Fortran file. That is not surprising; in fact, whether on Windows or Linux, I think of Cmake as "see if I can make it". If the package creators did not write a CMakeLists.txt that can work on Windows with Ifort, I usually give up. I am not interested in reading the hundreds of pages of Cmake documentation.


If you are content to build a reduced capability version using Ifort, you can do the following;

  1.  In the src directory, enter the command ifort /O2 /Qcoarray:single /c *.f90 a few times, until the error messages disappear.
  2. Build the library, with the command lib *.obj /out:neural.lib .
  3. Change to the examples directory, and build one of the examples, with the command ifort /Qcoarray:single /I..\src simple.f90 ..\src\neural.lib . Run the example.
  4. Repeat with other examples as you please.

That this ad hoc procedure worked should not lead anyone to conclude that it will work with any other similar source package. Given the little effort needed, it may be worth trying, and one could fix the CMakeLists.txt later.

Valued Contributor II

The problem with gfortran is finding it.  

How did you get mnist running if the data files are not findable at github?  

Black Belt
Valued Contributor II

Why if I set the number of images to 1 in the properties page do I get ::

image no 11 and then 4::


Black Belt Retired Employee

This isn't hard. I loaded the sources into a new project, chose simple.f90 as the main, set the options /standard-semantics and /Qcoarray, then built and ran it. The missing for_ICAF routines are due to not asking for coarray support.

Valued Contributor II

Thanks for all the help.  

I got them all running in VS 2019.  As noted I needed to turn on co-arrays and standard semantics.

Interestingly, if I turn off standard semantics, the simple program seems to run twice as fast.  

As @FortranFan suggested I will post the only problem I had on the Discourse website, as I cannot find the mnist.tar.gz file on the owners github.  It is supposed to be in a directory call files, but it does not seem to exist on the git hub site for the developer.  

subroutine download_and_uncompress()
    character(*), parameter :: download_mechanism = 'curl -LO '
    character(*), parameter :: base_url=''
    character(*), parameter :: download_filename = 'mnist.tar.gz'
    character(*), parameter :: download_command = download_mechanism // base_url // download_filename
    character(*), parameter :: uncompress_file = 'tar xvzf ' // download_filename
    character(message_len) :: command_message
    character(:), allocatable :: error_message
    integer :: exit_status, command_status




Screenshot 2022-05-15 165908.png


and curl is not going to work in windows. 


Valued Contributor II

@FortranFan  thanks for the help. The Fortran Discourse community loaded the file overnight and put up some explanation as well.  


I am slowly reloading their project into a VS project so I can follow the analysis and put in some comments for my records.  

What is the flag standard semantics supposed to do?

If I leave it unset the binary files reading crashes at 12500 and if I set it it reads the 50000 correctly, is that somehow connected to byte rec length?

If I can get it to run slowly without  coarrays then I can start to look at my data sets.  

If you have coarrays turned on then debugging does not stop. Is that normal?

Valued Contributor II

I am running Windows 11 - latest preview, 

one can use the new windows terminal

But it is not playing nicely with write statements from the Fortran program, it is only outputting some of the statements.  

I have returned to the windows console.

Has anyone else started to use the new console? 



Valued Contributor II
inquire(file='mnist_training_images.dat', exist=file_exists)
    if (.not. file_exists) call download_and_uncompress()

How can you have a if statement without a then?

Black Belt

@JohnNichols wrote:
if (.not. file_exists) call download_and_uncompress()

How can you have a if statement without a then?

Looks like a "logical if" statement, which has been in the language for a while.  See of the Fortran 66 standard or of F2018.

Black Belt Retired Employee

/standard-semantics is shorthand for a bunch of options that tell the compiler to behave the way the current standard says, rather than the way Intel/Compaq/DEC Fortran has "always done it", due to changes in the standard over the years. For details see standard-semantics (

The particular setting you seem to be interested in is /assume:byterecl.

Valued Contributor II

The development team uploaded a copy of the mnist database for use with the program.  

I took all the coarray stuff out, so I could follow the progression of the program. 

First question - does turning on coarrays turn off the VS debugger?  

I slowly copied the program across to a new Fortran sln and added write statements so I could follow along.  

The program has a input unit --> analysis unit --> output unit

The analysis unit is a set of do loops, would it not be better to use OPENMP on the analysis section alone?  

The analysis loops for 30 epochs, and reaches an accuracy of 97%. The limited output does not provide clues as to the 3% failures, this needs some more output.  

It runs nicely in a single core for the moment, so thanks. 

What is bytrecl change in standard semantics, clearly it is the record length, but from what to what?  

I have never played with logical if statements,  interesting?


Valued Contributor II

I got a stack overflow so I had to turn on heaps-array.  

There is a minor error in the Intel Documentation.  

Screenshot 2022-05-17 110725.png


The note should say 2018 semantics  as that is what comes up in the VS property page. 


Black Belt Retired Employee

Turning on coarrays doesn't turn off the debugger, but it makes debugging difficult.  See How to Gain Control of Debugging a Fortran Coarray Application (

Valued Contributor II

I am adding plots to mnist, to look at the ones that do not match. 



subroutine setcolors(Colors)
    implicit none

    integer, intent(inout) :: colors(30,3)



I spelt implicit none incorrectly, but the errors that returned all related to colors not being array sized matched, why can the compiler not pick up simple spelling errors on things like implicit none?  

Black Belt Retired Employee

How do you think it should be spelled?

Valued Contributor II

The compiler did nothing with implcit none.  Just an observation.  


I got the following error: 



Screenshot 2022-05-19 135402.png


When I turned on information for parameter constants - I include the program that showed the error. 

It runs if I turn off the switch.

The program has parameters scattered within, I am slowly trying to clean them all into base as I was taught by @mecej4 , but it takes a while.  

Dell Precision 5760 Core I7, windows 11 latest preview, VS 2019 latest and IFORT not updated to .2.  


I have not touched anything in that code block from the original developer Milan C. 

Complete code included.  


Screenshot 2022-05-19 135443.png


Please attach just the source files that are needed to reproduce the internal compiler error (ICE). We don't need the entire application and data files.


Valued Contributor II