LECTURES

 

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
                                                                                                                                                                                                                                        Brian Kernighan

 

One can develop parallel programs with MPI either in Fortran or C/C++ and launch them on clusters or supercomputers under Linux or AIX. Because scientific computations usually have very complicated logical structure and their debugging is typically very demanding, what turns out to be essentially helpful is an Integrated Development Environment (IDE). Because of this, all sample programs of my lectures can be debugged in IDE of Visual Studio and then can be copied to a cluster or a supercomputer without any changes and launched under Linux or AIX. It is achieved with the help of blocks that are bordered by preprocessor directives #ifdef and #endif in my codes. Nevertheless, beginners can ignore these blocks during the first reading.

 

An installation file of free Visual Studio Community 2022 can be downloaded here. After its installation, open Visual Studio, select Create a new project C++ Console App, push Next, and select Project name, e.g., hello_world_simplest, and Location. Then you can: 1) run a default Hello World program provided by Visual Studio pushing a green arrow, 2) copy the code of my project hello_world_simplest (PDF) to hello_world_simplest.cpp and run it, or 3) download my project hello_world_simplest (Visual_Studio), unzip it, open Visual Studio, push Open a project or solution, locate and double click hello_world_simplest.sln, unfold Source Files in Solution Explorer on the left, double click on hello_world_simplest.cpp in Solution Explorer, and push the button with a green arrow. Alternatively, you can select Build Build Solution or push F7 to compile the program. If there were errors or warnings in your program, they would be listed in Errors resp. Warnings at the bottom of your IDE. You can double click on them to locate their positions in your program or double click on a code in front of them to see a help. If you get into problems during debugging, don't forget to step through your program line by line and observe the current values of your program's variables. When you correct all errors, you can compile and run the program.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The basics of C/C++

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Recommended textbooks: Herout, P.: Učebnice jazyka C, 1. díl (buy) or Deitel, P. J. & Deitel, H. M., 2012. C: How to Program (buy).

 

Hello world simplest runs only in Visual Studio. If you wanted to make it running under various operating systems, it would be sufficient to use preprocessor directives as in the next sample.

 

hello_world_basics (Visual Studio, Linux, PDF):
You can compile this code in Linux by
      g++ hello_world_basics.cpp -o hello_world_basics
and launch it by
      ./hello_world_basics

 

Hereinafter, the most important samples are emphasized by !!! and the most demanding ones by *, ** or ***. The samples indicated by + only comprise programs that can appear to be useful sometime in the future: almost all of them will be skipped during the lecture.

 

Basic types and operators: Data_type_ranges, Data_type_constants, Standard_types, and Operators in C and C++.

 

Sample programs (flowcharts, Visual Studio, Linux):

hello_world_classes: Because the sample 7A consists of 3 files - hello_world_classes.cpp, hello_class.cpp, and hello_class.h - you have to compile it in Linux by
      g++ hello_class.cpp hello_world_classes.cpp -o hello_world_classes
and launch it by
      ./hello_world_classes


Useful tables: Keywords.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Object-oriented programing in C++

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Recommended textbooks: Eckel, B.: Thinking in C++, Volume 1 (download TICPP-2nd-ed-Vol-one-html.zip from https://archive.org/details/TICPP2ndEdVolOne). The sample programs mentioned below whose names begin with C are taken from this textbook. For example, C11_HowMany.cpp means that the attendees can double click on Contents.html, select Chapter 11, and find HowMany.cpp to see its code and further commentaries in case of a need.

 

Sample programs (Visual Studio, Linux):

Useful tables: Inheritance and Overloading.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

MPI for C/C++

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Recommended textbooks: Quinn, M.J.: Parallel Programming in C with MPI and OpenMP (buy).

 

Instalation files: The installation files of MS MPI can be downloaded here. It is necessary to restart your computer after the installation of MS MPI. Then you can test its functionality in a Command Promt. Write (Settings for Visual Studio):

 

C:\Windows\System32> set MSMPI

 

If the echo of the system is

 

MSMPI_BENCHMARKS=C:\Program Files\Microsoft MPI\Benchmarks\
MSMPI_BIN=C:\Program Files\Microsoft MPI\Bin\
MSMPI_INC=C:\Program Files (x86)\Microsoft SDKs\MPI\Include\
MSMPI_LIB32=C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x86\
MSMPI_LIB64=C:\Program Files (x86)\Microsoft SDKs\MPI\Lib\x64\

 

C:\Windows\System32>

 

it means that your MS MPI has been installed successfully. Then:

 

1. Open Visual Studio, click on Create a new project, write C++ instead of Search for templates, select Console App, and push Next. Let Project name is, e.g., myMPI. Select Location and push Create.
2. Do not forget to specify Solution Platform, e.g., x64 in a selector list of a small upper left window.
3. In the main menu, open Project myMPI Properties C/C++. In the upper central edit memo named Platform, set your operating system, e.g., Active(x64), and, depending on it, add $(MSMPI_INC);$(MSMPI_INC)\x64 or $(MSMPI_INC);$(MSMPI_INC)\x86 into Additional Include Directories.
4. Open Project myMPI Properties Linker Input and add msmpi.lib into Additional Dependencies.
5. Open Project myMPI Properties Linker General and, depending on your operating system, add $(MSMPI_LIB64) or $(MSMPI_LIB32) into Additional Library Directories.

 

Afterwards, you can copy the code from a PDF hyperlink of 1A_Hello_world.cpp to your myMPI. Try compiling it. If the compiler has announced errors for mpi.h, MPI_Init, etc., your MPI has not started to collaborate with Visual Studio yet, and so try to wait to the next day and repeat the compilation.

 

MPI_Routines (taken from www.mpich.org/static/docs/v3.2).
MPI_Constants (taken from www.mpich.org/static/docs/latest/www3/Constants.html).

 

Sample programs (Visual Studio, Linux):

A video of my Slovak lecture on parallel programing is here.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Bioinformatics

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Based on Chipster and their tutorial videos.

 

Sample analyses: