Commit de37a257 authored by ahmad.abdulla's avatar ahmad.abdulla

Hw

parents
This source diff could not be displayed because it is too large. You can view the blob instead.
# Makefile
# Source file
SRC = 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 NUM_RECTANGLES 1000000
int main() {
double total_area = 0.0;
double width = 1.0 / NUM_RECTANGLES;
#pragma omp parallel for reduction(+:total_area)
for (int i = 0; i < NUM_RECTANGLES; i++) {
double x = (i + 0.5) * width; // Midpoint of the rectangle
double height = x * x;
double area = width * height;
total_area += area;
}
printf("Total area under the curve: %f\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