Commit 9981fdc2 authored by ali's avatar ali

Initial commit

parents
This diff is collapsed.
# Makefile
# Source file
SRC = openMP_integration.c
# Compiler
CC = gcc
# Executable name
EXE = ./out
all: $(EXE)
$(EXE): $(SRC)
$(CC) -fopenmp -o $(EXE) $(SRC)
clean:
rm -f $(EXE)
run:
$(EXE)
#include <stdio.h>
#include <omp.h>
#define N 100000000 // Number of rectangles for the approximation
double calculate_partial_area(double x, double width) {
double height = x * x;
return width * height;
}
int main() {
double total_area = 0.0;
double width = 1.0 / N;
#pragma omp parallel for reduction(+:total_area)
for (int i = 0; i < N; ++i) {
double x = (i + 0.5) * width; // Midpoint of the rectangle
total_area += calculate_partial_area(x, width);
}
printf("Numerical integration using OpenMP:\n");
printf("Total area under the curve (X^2) for %d rectangles: %f\n", N, total_area);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment