Newer
Older
\begin{frame}
\titlepage
\centering
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\textit{Here's the code written by the postdoc who has just left - compile it and run it on the SCITAS clusters}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
Today we will look at
\end{block}
\begin{itemize}
\item<2-> Hardware
\item<3-> Parallel programming
\item<4-> Compiling and linking
\item<5-> Running on a cluster
\end{itemize}
\end{frame}
%---------------------
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\includegraphics[width=11cm]{images/ccNUMA.pdf}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
Pinning processes to cores
\end{block}
\begin{itemize}
\item<2-> \tt{1} - task is allowed
\item<3-> \tt{0} - task is excluded
\end{itemize}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\item<2-> \tt{10000000}
\item<3-> \tt{01000000}
\item<4-> \tt{00110000}
\item<5-> \tt{11110000}
\item<6-> \tt{00001111}
\item<7-> \tt{11111111}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
CPU masks for a 8 core system
\begin{itemize}
\item \tt{10000000 = 0x80}
\item \tt{01000000 = 0x40}
\item \tt{00110000 = 0x30}
\item \tt{11110000 = 0xF0}
\item \tt{00001111 = 0xF}
\item \tt{11111111 = 0xFF}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
\Large
\textbf{S}ingle\\
\textbf{I}nstruction\\
\textbf{M}ultiple\\
\textbf{D}ata\\
\normalsize
\end{block}
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
%---------------------
\begin{frame}
\includegraphics[width=11cm]{images/SIMD_Intel.pdf}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{itemize}
\item<1-> \( 2.6 \times 10^9\) Hz
\item<2-> \(\times \)14 Cores per Socket
\item<3-> \(\times \)2 Sockets
\item<4-> \(\times \)8 Doubles per cycle
\item<5-> \(\times \)2 FP math units per core
\item<6-> \(\times \)2 FMA
\item<7-> \( = 2.3\) TFLOPS
\end{itemize}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
\end{center}
\end{block}
\end{frame}
%---------------------
HPCG can use roughly 2\% of the peak performance
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
HPCG is representative of lots of scientific codes
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
\large
\normalsize
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
Every task sees all the data
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
\normalsize
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
Workers have their own data and can't see data belonging to other workers
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
If they need to ask to see something they have to send a message
\end{center}
\end{block}
\end{frame}
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
%---------------------
\begin{frame}
\begin{block}{}
MPI is the {\it de facto} standard for distributed memory parallelism
\end{block}
\begin{block}{}
OpenMP is the {\it de facto} standard for shared memory parallelism
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
MPI is a standard with many implementations
\begin{itemize}
\item<2-> MPICH2
\item<3-> MVAPICH2
\item<4-> Intel MPI
\item<5-> OpenMPI
\item<6-> Platform MPI
\end{itemize}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
Modules on the SCITAS clusters
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
Modules are hidden until the dependencies are loaded:
\begin{itemize}
\item<2-> module load compiler
\item<3-> module load MPI implementation
\item<4-> module load BLAS library
\end{itemize}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
The recipe
\begin{block}{}
\begin{itemize}
\item<2-> The name of the source file(s)
\item<3-> The libraries to link against
\item<4-> Where to find these libraries
\item<5-> Where to find the header files
\item<6-> A nice name for the executable
\end{itemize}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\tt{compiler \\ -l libraries \\ -L <path to libraries> \\ -I <path to header files> \\ -o <name of executable> \\ mycode.c}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\tt
\$ pwd \\
/home/user/qmcode
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
\tt
\$ ls \\
lib \\
include \\
src \\
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
\tt
\$ ls src/ \\
qmsolve.c
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
\tt
\$ ls lib/ \\
libfastqm.so
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
\tt
\$ ls include/ \\
fastqm.h
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
\tt
\$ icc \\ -lfastqm \\ -L/home/user/qmcode/lib \\ -I/home/user/qmcode/include \\-o qmsolve \\src/qmsolve.c
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
Linking makes life better
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
Write your own or use already written ones
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
The recipe
\begin{block}{}
\begin{itemize}
\item<2->{\tt-l} name of the library
\item<3->{\tt-L} location of the library
\item<4->{\tt-I} location of the header files containing the library function definitions
\end{itemize}
\end{block}
\end{frame}
\begin{center}
At runtime we need to set \\
\vspace{5mm}
{\tt LD\_LIBRARY\_PATH}\\
\vspace{5mm}
so the system knows where to find the library
\end{center}
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
\begin{center}
What's linked?
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}[fragile]
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
Libraries to make your life better
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{itemize}
\item<2->{\tt MKL}
\item<3->{\tt OpenBLAS}
\item<4->{\tt FFTW}
\item<5->{\tt Eigen}
%---------------------
\begin{frame}[fragile]
\begin{block}{}
\small
\begin{verbatim}
$ module load gcc fftw
$ gcc mycode.c \
-lfftw3 \
-L${FFTW_ROOT}/lib \
-I${FFTW_ROOT}/include \
-o mycode.x
\end{verbatim}
\normalsize
\end{block}
\end{frame}
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
\begin{frame}
\begin{block}{}
\begin{center}
Making your own library
\end{center}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{}
\begin{verbatim}
gcc -fPIC -c fastqm.c
\end{verbatim}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{}
\begin{verbatim}
gcc -shared -o libfastqm.so
fastqm.o
\end{verbatim}
\end{block}
\end{frame}
%---------------------
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
If you have more than one source file then use a build system
\end{center}
\end{block}
\end{frame}
\begin{frame}
Autotools
\begin{block}{}
\begin{itemize}
\item<2->{\tt ./configure}
\item<3->{\tt make}
\item<4->{\tt make install}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}
cmake
\begin{block}{}
\begin{itemize}
\item<2->{\tt cmake}
\item<3->{\tt make}
\item<4->{\tt make install}
\end{itemize}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
Optimising code
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
Do you want to optimise so that:
\begin{itemize}
\item<2-> the executable is as small as possible?
\item<3-> the code runs as fast as possible?
\item<4-> the code has "perfect" numerical accuracy?
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
\end{itemize}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
Compilers are lazy
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}[fragile]
\begin{block}{}
\footnotesize
\begin{verbatim}
float matest(float a, float b, float c)
{
a = a*b + c;
return a;
}
\end{verbatim}
\normalsize
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
\large
\tt gcc -s matest.c
\normalsize
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}[fragile]
\begin{block}{}
\tiny
\begin{verbatim}
matest(float, float, float):
push rbp
mov rbp,rsp
movss DWORD PTR [rbp-0x4],xmm0
movss DWORD PTR [rbp-0x8],xmm1
movss DWORD PTR [rbp-0xc],xmm2
movss xmm0,DWORD PTR [rbp-0x4]
mulss xmm0,DWORD PTR [rbp-0x8]
addss xmm0,DWORD PTR [rbp-0xc]
movss DWORD PTR [rbp-0x4],xmm0
mov eax,DWORD PTR [rbp-0x4]
mov DWORD PTR [rbp-0x10],eax
movss xmm0,DWORD PTR [rbp-0x10]
pop rbp
ret
\end{verbatim}
\normalsize
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
Let's make things faster
\begin{itemize}
\item<2-> {\tt -O0}
\item<3-> {\tt -O1}
\item<4-> {\tt -O2}
\item<5-> {\tt -O3}
\end{itemize}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
\large
\tt gcc -s -O3 matest.c
\normalsize
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}[fragile]
\begin{block}{}
\small
\begin{verbatim}
matest(float, float, float):
mulss xmm0,xmm1
addss xmm0,xmm2
ret
\end{verbatim}
\normalsize
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
Let's take advantage of the hardware
\begin{itemize}
\item<2-> {\tt -xAVX}
\item<3-> {\tt -xCORE-AVX2}
\item<4-> {\tt -xCORE-AVX512}
\item<5-> {\tt -xHOST}
\end{itemize}
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
\begin{center}
\large
\tt gcc -s -O3 -xAVX2 matest.c
\normalsize
\end{center}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{}
\small
\begin{verbatim}
matest(float, float, float):
vfmadd132ss xmm0,xmm2,xmm1
ret
\end{verbatim}
\normalsize
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
This is an improvement on the default
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}[fragile]
\begin{block}{}
\tiny
\begin{verbatim}
matest(float, float, float):
push rbp
mov rbp,rsp
movss DWORD PTR [rbp-0x4],xmm0
movss DWORD PTR [rbp-0x8],xmm1
movss DWORD PTR [rbp-0xc],xmm2
movss xmm0,DWORD PTR [rbp-0x4]
mulss xmm0,DWORD PTR [rbp-0x8]
addss xmm0,DWORD PTR [rbp-0xc]
movss DWORD PTR [rbp-0x4],xmm0
mov eax,DWORD PTR [rbp-0x4]
mov DWORD PTR [rbp-0x10],eax
movss xmm0,DWORD PTR [rbp-0x10]
pop rbp
ret
\end{verbatim}
\normalsize
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
\footnotesize
\it
or at least not as intelligent as you might like
\normalsize
\end{center}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{}
\tiny
\begin{verbatim}
void myfunc( double *a1, double *a2, double *prod, int c)
{
for(int x=0; x < c; x++)
{
prod[x] = a1[x] * a2[x];
}
}
\end{verbatim}
\normalsize
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
\large
{\tt gcc -O3 -xCORE-AVX512 matest.c } \\
\normalsize
\footnotesize
\it
sometimes isn't enough :-(
\normalsize
\end{center}
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
\begin{center}
Manual intervention is required...\\
\end{center}
\end{block}
\end{frame}
\begin{frame}[fragile]
\begin{block}{}
\tiny
\begin{verbatim}
void myfunc( double *restrict a1, double *restrict a2,
double *prod, int c)
{
for(int x=0; x < c; x=x+8)
{
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
prod[x+1] = a1[x+1] * a2[x+1];
prod[x+2] = a1[x+2] * a2[x+2];
prod[x+3] = a1[x+3] * a2[x+3];
prod[x+4] = a1[x+4] * a2[x+4];
prod[x+5] = a1[x+5] * a2[x+5];
prod[x+6] = a1[x+6] * a2[x+6];
prod[x+7] = a1[x+7] * a2[x+7];
}
}
\end{verbatim}
\normalsize
\end{block}
\end{frame}
\begin{frame}
\begin{block}{}
\begin{center}
\large
{\tt icc -O2 -xCORE-AVX512 -qopt-zmm-usage=high } \\
\normalsize
\end{center}
\end{block}
\end{frame}
\begin{frame}[fragile]
The loop then becomes:
\begin{block}{}
\footnotesize
\begin{verbatim}
vmovups zmm0, ZMMWORD PTR [rdi+r8*8]
vmulpd zmm1, zmm0, ZMMWORD PTR[rsi+r8*8]
vmovupd ZMMWORD PTR[rdx+r8*8], zmm1
\end{verbatim}
\normalsize
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
mpicc is your friend\\
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
mpicc is the "MPI code compiler"
\begin{itemize}
\item<2-> {\tt mpicc}
\item<3-> {\tt mpiicc}
\item<4-> {\tt mpiifort}
\item<5-> {\tt mpicxx}
\end{itemize}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
mpicc is really a wrapper for the standard (GCC and Intel) compilers
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}[fragile]
\begin{block}{}
\tiny
\begin{verbatim}
$ mpicc -show mycode.c
/ssoft/spack/paien/v2/opt/gcc/bin/gcc mycode.c
-I/ssoft/spack/paien/v2/opt/mvapich2/include
-L/ssoft/spack/paien/v2/opt/mvapich2/lib
-lmpi
\end{verbatim}
\normalsize
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
OpenMP support comes from the standard compiler
\end{center}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
Syntax is compiler dependent
\begin{itemize}
\item<2-> {\tt gcc -fopenmp mycode.c}
\item<3-> {\tt icc -qopenmp mycode.c}
\item<4-> {\tt gfortran -fopenmp mycode.f95}
\item<5-> {\tt ifort -qopenmp mycode.f95 }
\end{itemize}
\end{block}
\end{frame}
%---------------------
\begin{frame}
\begin{block}{}
\begin{center}
Running parallel codes
\end{center}
\end{block}
\end{frame}