diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1e9838b4727d6ed946df6aec34bfc939601e542f..ba2639af321dec5eb9ca1e7495a3b2ed1680e65b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,13 +20,22 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
 
 # TBB support
-set( WITH_TBB "OFF" CACHE BOOL "use TBB for on-node threading" )
-if( "${WITH_TBB}" STREQUAL "ON" )
+set(WITH_TBB "ON" CACHE BOOL "use TBB for on-node threading")
+if("${WITH_TBB}" STREQUAL "ON")
     find_package(TBB REQUIRED)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_TBB ${TBB_DEFINITIONS}")
-    link_directories(${TBB_LIBRARY})
 endif()
 
+# MPI support
+set(WITH_MPI "ON" CACHE BOOL "use MPI for distributed processing")
+if("${WITH_MPI}" STREQUAL "ON")
+    find_package(MPI REQUIRED)
+    include_directories(SYSTEM ${MPI_C_INCLUDE_PATH})
+    add_definitions(-DWITH_MPI)
+    # unfortunate workaround for C++ detection in system mpi.h
+    add_definitions(-DMPICH_SKIP_MPICXX=1 -DOMPI_SKIP_MPICXX=1)
+    set_property(DIRECTORY APPEND_STRING PROPERTY COMPILE_OPTIONS "${MPI_C_COMPILE_FLAGS}")
+endif()
 
 # targets for extermal dependencies
 include(ExternalProject)
diff --git a/miniapp/CMakeLists.txt b/miniapp/CMakeLists.txt
index a3f8447e62da12d6fc1a489a66d7b4b35d50ec9c..8ce6e389644c164a7177b567889fd3d7762098f1 100644
--- a/miniapp/CMakeLists.txt
+++ b/miniapp/CMakeLists.txt
@@ -11,6 +11,11 @@ add_executable(miniapp.exe ${MINIAPP_SOURCES} ${HEADERS})
 target_link_libraries(miniapp.exe LINK_PUBLIC cellalgo)
 target_link_libraries(miniapp.exe LINK_PUBLIC ${TBB_LIBRARIES})
 
+if(WITH_MPI)
+    target_link_libraries(miniapp.exe LINK_PUBLIC ${MPI_C_LIBRARIES})
+    set_property(TARGET miniapp.exe APPEND_STRING PROPERTY LINK_FLAGS "${MPI_C_LINK_FLAGS}")
+endif()
+
 set_target_properties(miniapp.exe
    PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/miniapp"
diff --git a/src/algorithms.hpp b/src/algorithms.hpp
index 5d609b1effe57f12d3998e10d856b659c042120e..738f163fa8381363b099c981d57df36923bc921d 100644
--- a/src/algorithms.hpp
+++ b/src/algorithms.hpp
@@ -208,7 +208,7 @@ std::vector<typename C::value_type> expand_branches(const C& branch_index)
 
     std::vector<typename C::value_type> expanded(branch_index.back());
     for (std::size_t i = 0; i < branch_index.size()-1; ++i) {
-        for (std::size_t j = branch_index[i]; j < branch_index[i+1]; ++j) {
+        for (auto j = branch_index[i]; j < branch_index[i+1]; ++j) {
             expanded[j] = i;
         }
     }