Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28507 Discussions

Working with sample codes for vectorization

Fortran10
Beginner
2,032 Views

I am using this exercise of vectorization:

 

oneAPI-samples/DirectProgramming/Fortran/DenseLinearAlgebra/vectorize-vecmatmult at master · oneapi-src/oneAPI-samples · GitHub

 

I am using the Windows 10 operating system and command line ( Not the MVS ).

 

My questions is:

 

  • What is the Windows version of the command:

ifort -real-size 64 -qopt-report=2 -qopt-report-phase=vec -D ALIGNED -ipo src/matvec.f90 src/driver.f90 -o MatVector

 

specifically how to instruct the aligned command there? Or how to use command line directives? How to specify the option?

 

 

 

 

0 Kudos
1 Solution
TobiasK
Moderator
1,950 Views

Hi @Fortran10


most Linux command line options translate to Windows with the same name but '/' instead of '-'

In the developers guide and reference we always list the option for Linux as well for Windows:

e.g. -D becomes /D

https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-2/d.html


View solution in original post

0 Kudos
16 Replies
andrew_4619
Honored Contributor II
1,974 Views

/[no]align
analyze and reorder memory layout for variables and arrays
/align:<keyword>
specify how data items are aligned
keywords: all (same as /align), none (same as /noalign),
[no]commons, [no]dcommons,
[no]qcommons, [no]zcommons,
rec1byte, rec2byte, rec4byte,
rec8byte, rec16byte, rec32byte,
array8byte, array16byte, array32byte,
array64byte, array128byte, array256byte,
[no]records, [no]sequence

 

TobiasK
Moderator
1,951 Views

Hi @Fortran10


most Linux command line options translate to Windows with the same name but '/' instead of '-'

In the developers guide and reference we always list the option for Linux as well for Windows:

e.g. -D becomes /D

https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-2/d.html


0 Kudos
Fortran10
Beginner
1,914 Views

The developer guide says D :

 

Defines a symbol name that can be associated with an optional value.

 

What is the symbol here? and how optional value is related to ALIGNED. These two things are not very straightforward from here.

 

My initial guess was, "It is used to define Directives." D for Directive and is used in combination with ALIGNED to inform the compiler that I want to use the Compiler directive i.e. ALIGNED.

 

 

 

 

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,893 Views

@TobiasK last post referred to "/" verses "-" for option indicator on command line. The D was simply a place holder, and not to be construed with an actual switch.

 

FWIW

 

/Dnewsymbol /Dnewvalue=1

...

!$if defined(newsymbol) then

! conditional code 

!$endif

...

!$if (newvalue==1) then

! conditional code 

!$endif

 

Jim Dempsey

0 Kudos
TobiasK
Moderator
1,818 Views

 

In addition to what Jim said, if you look into the source code of driver.f90:

https://github.com/oneapi-src/oneAPI-samples/blob/master/DirectProgramming/Fortran/DenseLinearAlgebra/vectorize-vecmatmult/src/driver.f90

 

You notice some #if defined structure as Jim wrote.

That means, such a file must be processed by a preprocessor. Either you use a standalone preprocessor as cpp or fpp or you just instruct to compiler to call the preprocessor before the actual code compilation via /fpp or /cpp compiler flags.

 

It does not do anything at the compile step, all it affects is prior the compilation.

 

In the driver example you see some

 

!DIR$ IF DEFINED(ALIGNED)
 integer, parameter      :: ROWBUF=3
!DIR$ ELSE
 integer, parameter      :: ROWBUF=0
!DIR$ END IF

 

if you invoke the compiler with /fpp /D ALINGED the actual Fortran file will be: (because ALIGNED is defined by \D)

 

 integer, parameter      :: ROWBUF=3

 

if you invoke the compiler with /fpp /d XYZ the actual Fortran file will be: (because ALINGED is not defined by \D)

 

 integer, parameter      :: ROWBUF=0

 

So think of preprocessing as an automated text editor.

 

Best

Tobias

 

0 Kudos
Fortran10
Beginner
1,406 Views

using /fpp /DALIGNED shows this error:

 

fpp_ALIGNED.PNG

 

without using /fpp it does not show any error:

 

ALIGNED_QxHost.PNG

0 Kudos
Fortran10
Beginner
1,789 Views

Performance baseline

I do not actually see any improvement

Using /fpp 

fpp.PNG

 

without /fpp

no_fpp.PNG

 

My computer details are

11th Gen Intel(R) Core(TM) i5-11500 @ 2.70GHz

 

I tried this with both 16 and 64 bytes (driver.f90 file), but still no improvement.

!DIR$ attributes align : 16 :: a,b,c

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,750 Views

If you are on an Intel CPU, try adding option /QxHost

If AMD, try adding /QxAVX

 

Also, it may be helpful to build optimized code with generating and keeping debug symbols, then running under VTune. Ignore the runtimes but use VTune to show the Disassembly.

With this, you can verify two things:

a) Was the ALIGNED code vectorized.

b) Was the not ALIGNED code not vectorized.

 

Jim Dempsey

 

0 Kudos
Fortran10
Beginner
1,710 Views

Thanks for the hint. I will have a look at VTune. That tool seems to be very informative in understanding vectorization.

0 Kudos
Steve_Lionel
Honored Contributor III
1,619 Views

@jimdempseyatthecove wrote:

If you are on an Intel CPU, try adding option /QxHost

If AMD, try adding /QxAVX

 

 


If non-Intel CPU, /arch:AVX . /QxAVX will cause a run-time error when the program starts on non-Intel CPUs.

P.S. Jim, please check your messages here on the forum.

0 Kudos
Barbara_P_Intel
Moderator
1,734 Views

@Fortran10, I see a couple of typos in the compiler options in your screenshot using /fpp. Should be 

/DALIGNED

You also might want to update to the latest release of ifort. Yours is 1.5+ years old.

 

0 Kudos
Fortran10
Beginner
1,642 Views

I did following steps to update:

 

1. download the BaseKit

download_baseKit.png

2. Install

installed_baseKit.PNG

 3. Download the HPC Kit shows that error 

HPC_kit.PNG

 

4. Separate downloading the Fortran compiler

 

fortran_compiler_Separate_download.PNG

 

5. Download folder looks like

 

download_baseKit_and_Fortran_compiler.PNG

 

 

 

 

 

6. Running Fortran code shows error

intel_error.PNG

7. Start menu: 

 

Intel_settings_in_start_menu.PNG

 

So what should be done now ? 

 

0 Kudos
Fortran10
Beginner
1,406 Views

I removed the installed version.

 

1)  Now i have installed the version 2023.1.0.47256.

 

version.PNG

 

That seems to work fine.

 

2)   However using /fpp /DALIGNED shows error:

 

 

fpp_ALIGNED.PNG

 

3)   Without using /fpp , I do not see any error.

 

ALIGNED_QxHost.PNG

 

4)    Also, the use of /Qipo does not improve performance.

 

DALIGNED_QxHost_Qipo.PNG

0 Kudos
Fortran10
Beginner
1,711 Views

@Barbara_P_Intel Thanks for the clarification.

 

I have performed the following tests with these outputs.

 

Seems like

 

  • /fpp /DALIGNED should always be used with /QxHost.
  • /QxHost alone is producing the same performance without using /fpp /DALIGNED.

QxHost and Aligned test.PNG

 

So does that mean aligning data is not compatible here?

 

  • The use of /Qipo however improves the performance

 

Qipo test.PNG

 

@Barbara_P_Intel Thanks for notifying me, I will try to install the new release this coming weekend and will perform the same results.

0 Kudos
Barbara_P_Intel
Moderator
1,673 Views

@Fortran10, there's still a typo regarding /DALIGNED in your screen shot.

 

0 Kudos
jimdempseyatthecove
Honored Contributor III
1,390 Views

You Are combining fpp and having /DALIGNED and testing !DIR$ IF DEFIGNED(ALIGNED)

The /DALIGNED is going to set ALIGNED=1

Then fpp is going to replace the text "ALIGNED" with its content "1", and the literal 1 is not a definable variable/macro.

When you use fpp in combination with compiler directives you should be aware of these types of conflicting usage.

 

Because these sources have no #xxx preprocessor directives, you can remove the /fpp from your command line.

 

Jim Dempsey

0 Kudos
Reply