Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F77966282
poisson.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 17, 13:13
Size
1 KB
Mime Type
text/x-c
Expires
Mon, Aug 19, 13:13 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
19955753
Attached To
rSCINTROPARALLEL Poisson code for introduction to parallelism
poisson.c
View Options
#include "io_ascii.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define N 256
int main() {
int i, j;
char k;
float ** u;
float ** uo;
float ** f;
float h;
h = 1. / (N + 1);
// Allocation of arrays of pointers (columns)
u = (float **)malloc((N + 1) * sizeof(float *));
uo = (float **)malloc((N + 1) * sizeof(float *));
f = (float **)malloc((N + 1) * sizeof(float *));
// allocation of the rows
for (i = 0; i < N + 1; i++) {
u[i] = (float *)malloc((N) * sizeof(float));
uo[i] = (float *)malloc((N) * sizeof(float));
f[i] = (float *)malloc((N) * sizeof(float));
}
// initialization of u0 and f
for (i = 0; i < N + 1; i++) {
for (j = 0; j < N + 1; j++) {
u[i][j] = 0;
uo[i][j] = 0;
f[i][j] = -2. * 100. * M_PI * M_PI * sin(10. * M_PI * i * h) *
sin(10. * M_PI * j * h);
}
}
for (k = 0; k < 200; ++k) {
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
// computation of the new step
u[i][j] = 0.25 * (uo[i - 1][j] + uo[i + 1][j] + uo[i][j - 1] +
uo[i][j + 1] - f[i][j] * h * h);
}
}
// copy new grid in old grid
for (i = 0; i < N + 1; i++) {
for (j = 0; j < N + 1; j++) {
uo[i][j] = u[i][j];
}
}
write_to_file(N + 1, u, k, -1., 1.);
}
// de-allocation of the rows
for (i = 0; i < N + 1; i++) {
free(u[i]);
free(uo[i]);
free(f[i]);
}
return 0;
}
Event Timeline
Log In to Comment