1 / 6

Understanding Fortran Array Notation and Implementation in CSCI 317 with Mike Heroux

This overview explores the fundamental concepts of array notation in Fortran, highlighting its similarities and differences compared to C/C++ syntax. Key points include how Fortran uses parentheses for indices and the default base index of one, contrasted with C/C++'s square brackets and zero-based indexing. The course content covers two-dimensional arrays, column-major storage, subarray definitions, and leading dimensions. Additionally, parallel computations using OpenMP for matrix multiplication (GEMM) are introduced, emphasizing performance optimization in programming practices.

watson
Télécharger la présentation

Understanding Fortran Array Notation and Implementation in CSCI 317 with Mike Heroux

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fortran Arrays CSCI 317 Mike Heroux CSCI 317 Mike Heroux

  2. Array Notation • Interface is similar to Java/C/C++. • Except: • Indices are enclosed with (…) not […]. • Fortran: myarray(i) • C/C++ : myarray[i] • Note: MYARRAY(i), myarray(i) and MyArRaY(i) are all the same array in Fortran. • Default index base is 1 not 0. • First Fortran element: myarray(1) • Address of myarray(1) == Address of myarray[0] (Fortran vs. C/C++) • Base can be changed: • real myarray(0:n-1) makes myarray(0) the first element. CSCI 317 Mike Heroux

  3. 2D Array • real A(3,4) • “Column Major”: • A(1,1) next to A(2,1), next to A(3,1) … • 1D in storage: • A(3,1) stored next to A(1,2) CSCI 317 Mike Heroux

  4. Subarrays • Leading dimension: • Also called stride. • Distance between two adjacent row elements. • Example: LD = 3. • Subarray: • Described by: • Address of first element: A(2,2) • LD: 3 • Number of columns: 2 CSCI 317 Mike Heroux

  5. Simple OMP GEMM #include <omp.h> void dgemmfkernel_(int * m, int * n, int * k, double * alpha, double * a, int * lda, double * b, int * ldb, double * beta, double * c, int * ldc); void dgemmckernel_(int * M, int * N, int * K, double *A, int * LDA, double *B, int* LDB, double *C, int * LDC) { int m = *M; int n = *N; int k = *K; intlda = *LDA; intldb = *LDB; intldc = *LDC; double alpha = 1.0; double beta = 0.0; intmlocal; inti,j,l; intnum_threads, chunksize; CSCI 317 Mike Heroux

  6. Simple OMP GEMM (2) #pragma omp parallel num_threads = omp_get_num_threads(); /*chunksize = (m+num_threads-1)/num_threads;*/ chunksize = m/num_threads; #pragma omp parallel for for (i=0; i<m; i+=chunksize) { /*mlocal = (m-i*chunksize>chunksize) ? chunksize : m - i*chunksize;*/ mlocal = chunksize; dgemmfkernel_(&mlocal, N, K, &alpha, A+i, LDA, B, LDB, &beta, C+i, LDC); } return; } CSCI 317 Mike Heroux

More Related