A C++ MPI code for 2D unstructured halo exchange

I expain my code for a 2D halo exchange of unstructed mesh blocks (boxes) using message passing interface (MPI). Any thickness of halo and periodic condition are supported. The blocks can have different sizes and location in space. A CPU can run multiple blocks.
Read more...

Essential bash customizations: prompt, ls, aliases, and history date

Bash prompt is made to show more info, ls output is customized to be colorful, history date added and aliases are recommanded to enhance efficiency.
Read more...

Script to copy a directory path in memory in Bash terminal

I explain how, with a script, copy the path of current directory in memory in a Bash terminal, without a mouse, and use it for other actions.
Read more...

What is the difference between .bashrc, .bash_profile, and .profile?

The start-up Bash commands, variables, aliases and cutomizations are put in .bashrc, .bash_profile, and .profile files. So whenever you open a new terminal, one of these files is sourced first, but which one?
Read more...

A C++ MPI code for 2D arbitrary-thickness halo exchange with sparse blocks

I am writing an example of halo exchange for message passing interface (MPI). Halo exchange is usual part of high performance math and CFD solvers. The example here deals with a 2D halo of arbitrary thickness and transfers corner nodes. The blocks can be sparse in space.
Read more...

Create clone of a C++ class in polymorphic way

I explain how we can make a clone/copy of the object of a polymorphic pointer at runtime. A virutal clone function is created to solve this. It can return raw pionters or unique pointers. Returning raw pointers lead to covariance.
Read more...

How to use type erasure pattern to decouple polymorphic classes in C++?

A dependency injection explained with an example. The dynamic dispatch goes through two pointer indirection when a class and its strategies are loosely coupled. The example is recreated using template type erasure where a class and its strategies are completely decoupled.
Read more...

What is tag-dispatch in C++?

Tag-dispatch is a metaprogramming technique to overload a function using different tag parameters. The right overload is chosen by a compiler at compile time. It can be replaced by if-constexpr of C++17.
Read more...

What is C++ metafunction and how to use it?

In C++ metaprogramming, a metafunction receives types and/or integral values, and after performing some logics returns types and/or integral values. Metafunctions along with constexpr functions become a strong tool for metaprogramming.
Read more...

What are C++ variadic templates and fold expressions?

A variadic template is a function or class template that accepts a parameter pack. There is no explicit for-loop command to iterate the pack parameters. Since C++17, fold expressions, which are way cleaner that recursive functions, are implemented to expand parameter packs.
Read more...

CMake part 3: create a config file to be found by find_package()

In this post, I show how to create CMake config and version file for a project with an example. In this way, the user of the library can import it easily with find_package() command.
Read more...

CMake part 2: Examples to build executable and library projects

In this post, instead of throwing instructions for some random commands, I aim to explain how to employ modern CMake step by step to build executables (applications) and static/shared/header-only libraries from C++ projects.
Read more...

CMake part 1: It is a programming language!

This post aims to coherently mention important concepts, syntax, and commands of CMake as a programming language. I focus on installation, defining variables, if-conditions, loops, functions, scopes and so on.
Read more...

Example for SWIG to wrap C++ library in .Net 6

A SWIG interface is created to wrap a native C++ library and be read by .Net 6. The code is compiled using CMake. The library is used in a C# program. This setup is cross-platform and tested on Linux and Windows.
Read more...

How to work with wxPython BoxSizer

In wxPython, BoxSizer is responsible for the horizontal and vertical layout of controls such as buttons, text boxes, combo boxes, panels, and other sizers. The different layouts, alignments, and flags of BoxSizer are demonstrated with examples.
Read more...

Build Clang 13 from source on Ubuntu

I step by step show how to download clang 13 source code and install it on Ubuntu 20.04.
Read more...

An MPI OpenMP example script for Slurm

A Slurm script is created to submit a parallel code multiple times to a cluster. The commands to submit the job and check its status are shown. The program is a parallel C++ code containing MPI and OpenMP directives.
Read more...

How to have detached persistent remote terminal

With screen and tmux commands, I explain how you keep remote Linux terminals alive and running while your local machine is disconnected from the remote machine.
Read more...

How to write C++ concurrent code with std::thread

Here, I explain how To write multithread programs in C++ to run multiple tasks simultaneously. Thread objects are described with examples. Moreover, I talk about how threads are constructed, joined and detached.
Read more...

What is the difference between concurrency and parallelism?

I explain the difference between serial, concurrent, and parallel code. The processor is defined. The readers are guided on what to look for to start writing concurrent and parallel codes.
Read more...

Master C++ const once and for all

A constant object doesn’t change during program runtime. Constantness also means read-only access to an object. I expain it with examples.
Read more...

Automate MPI custom type creation with C++

Here with the aid of C++20, variadic functions, and type-traits, I created a header library to automate creation of MPI custom (derived) datatype.
Read more...

C++ constexpr makes compile-time programming a breeze

The code written with constexpr is aimed to be evaluated at compile-time.Here constexpr conditions, variables and calsses are explained.
Read more...

Compile-time vs runtime programming in C++

Here I explain the difference between compile-time and runtime in C++ with examples. being a statically typed language, C++ contains meta-programming syntax and commands that let us to program the types and constant values for just compile-time.
Read more...

Use pybind11 for a detailed but simple example

A detailed C++ project, the robot, is created. Then, its classes and their components are declared in python: constructors, methods, public data members, and setter and getter (property).
Read more...

Python for file management

I show how Python functions can be used for file management: create, delete, copy, and move files. Therefore, you can automating complex tasks with Python programming.
Read more...

pybind11: call OpenMP function in Python

I want to use pybind11 to compile an OpenMP parallel code. Then, I load the created module in Python and run it. The code is in C++.
Read more...

Essential Linux commands to know

Here, I picked essential Linux Shell commands, you need to know to use a Bash terminal: navigation, copy, delete, variables, aliases, and so on.
Read more...

Journal quality x-y chart with Matplotlib

I write a python script that, using Matplotlib, creates high-quality x-y charts from a CSV file. LaTeX is supported. The chart details such as font, line and marker styles and ticks are modifiable.
Read more...

Build GCC 11 from source on Ubuntu

Here I am building and installing the latest GCC, 11.1, on Ubuntu 21.04 from the source. The procedure is explained step by step.
Read more...

SSH port forwarding to download files

I want to download files from a destination computer connected to a public SSH server. The destination is accessible only via the server by SSH tunnel.
Read more...

Span is a new norm in C++ codes

Span is a new feature of C++20 for reading and writing a sequence of objects. Here, I mention how to use std::span and its functions including subspan.
Read more...

Essential VS Code font and extensions for C++

I briefly enumerate the primary font and extensions that I install on my Visual Studio (VS) Code to develop a C++ code: Fira Code font, CMake tools, bookmarks, snippets, and so on.
Read more...

An overview of C++ perfect forwarding

With a simple example, it is demonstrated that how perfect forwarding can keep rvalueness of function’s parameters. The universal reference is also discussed.
Read more...

Is C++ static polymorphism useful?

With examples, I explain static vs dynamic polymorphism. I show that static one limits the flexibility of the program at runtime. However, it can improve the performance of the code whose behaviour can be resolved at compile-time.
Read more...

From lvalue, prvalue, and xvalue to move semantics in C++

With examples, I explain the difference between lvalue, rvalue, prvalue, and xvalue. The rvalue references are defined. Consequently, I describe std::move and its application in creating move constructors and assignments.
Read more...

What is a C++ weak pointer and where is it used? smart pointers part III

Weak pointers (weak_ptr) are smart pointers that observe other objects but don’t take ownership of them. Here, I explain how they are implemented and why we need them with examples.
Read more...

What is a C++ shared pointer and how is it used? smart pointers part II

Shared pointers (shared_ptr) are smart pointers which ameliorate memory management. Here, I explain them with examples and discuss their usage and performance.
Read more...

What is a C++ unique pointer and how is it used? smart pointers part I

Unique pointers (unique_ptr) manage a pointer’s allocated memory. Here, I define them and explain the operations, passing to / returning from a function, and performance. A factory example is also demonstrated.
Read more...

What are C++20 concepts and constraints? How to use them?

With examples, C++ concepts are used to constrain template classes and functions. It is shown that concepts improve the readability of code and facilitate finding bugs.
Read more...

Building a C++ project with Travis continuous integration (CI)

I explain with an example that how a C++ project is automatically built by Travis CI with the push of a commit.
Read more...

How to use C++ namespace for large projects

I exaplain how namespaces can organize a large project and prevent name conflicts.
Read more...

Create a contiguous array of a generic class in C++

I want to create a contiguous array of a class and its derived ones. I make sure the polymorphism behavior is captured too.
Read more...

A note on computer round-off error in physics

The way floating-point numbers are stored in the memory of a computer can lead to unwanted errors. Here we have an overview of the basics of storing numbers and how they affect the outcome of physics programs.
Read more...

Various ways to create arrays and vectors and their differences in C++

Different methods to create arrays in C++ are overviewed: c-style array, pointer array, std::vector, std::array, and Boost multiarray. How the memory is managed by each style and also their practical usage is discussed.
Read more...

MPI Traffic Program with C++

I want to solve a traffic problem with MPI and C++. The road is divided into sections which send their boundaries and receive their ghost points.
Read more...

Debug MPI program with Visual Studio Code

Debugging MPI program can be a nightmare. I explain how easily you can debug a parallel MPI program with visual studio (VS) code.
Read more...

C++ auto keyword makes your life easier

In C++, auto keyword infers the type of a variable from its initializer. auto can speed up coding and improve the maintainability of code. Here, I show cases that auto can make a difference.
Read more...

MPI race condition

When a buffer, which is involved in an uncompleted non-blocking communication, is used in another communication, there will be a race to read and write the buffer.
Read more...

MPI ping pong program using C++

I want to write an MPI ping pong program where two processes send a piece of data back and forth to each other.
Read more...

Handy cross-platform packages to connect to a remote Linux server

Interaction with a remote Linux server like transferring files, editing code, or accessing the remote desktop can be much easier with these free cross-platform packages.
Read more...

The difference between modes of MPI send

There are different modes of MPI send: MPI_Send, MPI_Isend, MPI_Ssend, MPI_Bsend, and so on. They can be local or non-local, blocking or non-blocking, and synchronous or asynchronous. Their definition and differences are explained here in detail.
Read more...

How and where to use C++ templates

Using templates in C++, you can create functions or classes having similar behaviours for different types. Here, all the useful features of templates are explained with examples.
Read more...

How to use Bookmark in Visual Studio

Visual Studio bookmark speeds up code development in big projects. Here, I mention the keyboard shortcuts.
Read more...

Connect to Microsoft Access database with C# .Net core

I want to connect to an MS Access database with C# in .Net core. Therefore, I will be able to create, read, update, and delete (CRUD) records.
Read more...

Lockout user after multiple failed authentication via .Net core Identity

Goal I want to configure .Net core Identity in a way that when a user inserts wrong passwords several times the account gets locked for 5 minutes.
Read more...

Add Identity pages to .Net core web app

By default, the identity pages are pre-compiled in .Net core 3.1 and not available to be modified. I want to bring them back so they can be edited.
Read more...

Create a table of content from headings of a Hugo post

Goal I want to write code to get a table of content (ToC) for each blog post automatically. It is created and shown on the right-hand side of the content of a post.
Read more...

How to add a video to a Hugo post

I want to add a video to a Hugo blog post. The video is hosted on my website, so it is not a Youtube or Vimeo.
Read more...

Tutorial: Setup of Entity Framework (EF) core for CRUD and authentication with Razor pages

Goal In this post, step by step I create a web app using Entity Framework core and razor pages. The app is a library that admin can CRUD books info on a database and authenticated users can browse the records.
Read more...

C++ inheritance crash course

Inheritance is the mechanism that the attributes and methods of a base class are passed to a derived class. Here, all useful details of C++ inheritance are mentioned with examples.
Read more...

Host a .Net core web application for less than $5 a month

I talk about Google Cloud Platform (GCP), Microsoft Azure and Heroku. You can register with them and try their services for free or very low prices.
Read more...

How to have math equations in your website

If you want to write math equations in your website or blog, plain text becomes immediately illegible when writing something more complex than addition and subtraction.
Read more...

Code LU decomposition step by step in object-oriented way in C#

Introduction In this post I want to revisit PLU or LU decomposition or factorisation, which is used to find unknowns of a system of linear equations, for two reasons.
Read more...

How Dry principle leads to clean and easy to debug code?

Dry is short for “Don’t repeat yourself”. There are occasions that a piece of code is rewritten several times. It is better to define that as a specific method or class. I explain it with examples.
Read more...

What is a recursive function?

Definition A recursive function is a function that calls itself with different arguments. Therefore, it is applied to a problem that each step of it is similar to the previous one.
Read more...

Implementing YAGNI and KISS principle to have maintainable code

After reading a lot of design patterns, loose-coupling ideas, and so, you cannot wait to implement all of them in the first program you are making.
Read more...

How Inversion of Control improves flexibility of numerical codes?

Introduction When programming, it’s very convenient to create class A which has a concrete member class B. However, this creates a tightly-coupled system since any change in B should be reflected in A.
Read more...

How visitor design pattern is useful for numerical programming?

Introduction The visitor design pattern separates operations from data storage. When the efficiency and memory consumption is not of concern this design pattern is not common.
Read more...

What is "object slicing" trap in C++?

Every now and then, I switch programming language from C# to C++, I fall in the trap of object slicing. It happens when a derived object is assigned by value to a base object where the extra information in the derived object is scrapped for worst.
Read more...

How to use C++ raw pointers properly?

A pointer is an 8-byte type on a 64-bit machine that holds the memory address of a target object. Here, I mention the most useful characteristics of pointers with examples.
Read more...

Create a lightweight weblog homepage with Bootstrap and Html

I want to create a lightweight homepage of a weblog with HTML, Bootstrap and a bit of custom CSS. No javascript, no database, no WordPress is used. It should be a lightweight and fast static website.
Read more...

How to create a simple component, using Blazor, HTML, and CSS: Word Block

Using .Net Blazor, I want to create a simple word-block which is a rectangle that contains a word with an X button at its right side. Clicking on X the word-block disappears.
Read more...