Skip to content

Commit e036965

Browse files
committed
First commit with mpi integrated.
1 parent e81c44b commit e036965

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,10 @@ modules.order
5050
Module.symvers
5151
Mkfile.old
5252
dkms.conf
53+
54+
55+
# CMake
56+
cmake-build-debug/
57+
58+
# IDEA
59+
.idea/

CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
project(RandomStringAssembly C)
3+
find_package(MPI REQUIRED)
4+
message(STATUS "Run: ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} EXECUTABLE ${MPIEXEC_POSTFLAGS} ARGS")
5+
6+
set(CMAKE_C_STANDARD 11)
7+
8+
add_executable(RandomStringAssembly main.c)
9+
target_link_libraries(RandomStringAssembly PUBLIC MPI::MPI_C)

main.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#include <mpi.h>
3+
4+
int main(int argc, char** argv) {
5+
// Initialize the MPI environment
6+
MPI_Init(NULL, NULL);
7+
8+
// Get the number of processes
9+
int world_size;
10+
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
11+
12+
// Get the rank of the process
13+
int world_rank;
14+
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
15+
16+
// Get the name of the processor
17+
char processor_name[MPI_MAX_PROCESSOR_NAME];
18+
int name_len;
19+
MPI_Get_processor_name(processor_name, &name_len);
20+
21+
// Print off a hello world message
22+
printf("Hello world from processor %s, rank %d out of %d processors\n",
23+
processor_name, world_rank, world_size);
24+
25+
// Finalize the MPI environment.
26+
MPI_Finalize();
27+
return 0;
28+
}

0 commit comments

Comments
 (0)