This project demonstrates different implementations to estimate the value of π using the Maclaurin series. The project includes four distinct versions:
-
Sequential (
sequential.c)
A basic single-threaded implementation. -
Multithreaded (
multithreaded.c)
Uses POSIX threads (pthread) along with a custom spinlock for parallel computation. -
Multiprocessed (Shared Memory) (
multiprocessed_shared_memory.c)
Utilizesfork()and shared memory viammap()with a spinlock to synchronize access. -
Multiprocessed (Pipes) (
multiprocessed_pipes.c)
Leveragesfork()and pipes for inter-process communication.
Use the following commands to compile each version:
gcc -o pi_sequential sequential.c common/maclaurin/maclaurin.c -lm
gcc -o pi_multithreaded multithreaded.c common/locks/locks.c common/maclaurin/maclaurin.c -lpthread -lm
gcc -o pi_multiprocess_shm multiprocessed_shared_memory.c common/locks/locks.c common/maclaurin/maclaurin.c -lrt -lm
gcc -o pi_multiprocess_pipes multiprocessed_pipes.c common/maclaurin/maclaurin.c -lmReplace <number_of_terms> or <number_of_threads/processes> with your desired values:
./pi_sequential <number_of_terms>
./pi_multithreaded <number_of_threads> <number_of_terms>
./pi_multiprocess_shm <number_of_processes> <number_of_terms>
./pi_multiprocess_pipes <number_of_processes> <number_of_terms>This project is licensed under the MIT License.
