Compare View

switch
from
...
to
 
Commits (2)

Diff

Showing 6 changed files Inline Diff

lab1/pi_mpi.c View file @ c7c188d
#include <stdio.h> 1 1 #include <stdio.h>
#include <string.h> 2 2 #include <string.h>
#include <mpi.h> 3 3 #include <mpi.h>
#define N 100000000 4 4 #define N 100000000
5 5
int main (int argc, char** argv) 6 6 int main (int argc, char** argv)
{ 7 7 {
int rank; 8 8 int rank;
int size; 9 9 int size;
long long int n; 10 10 long long int n;
long long int i; 11 11 long long int i;
12 12
double l_sum,total_sum, x, h; 13 13 double l_sum,total_sum, x, h;
14 14
MPI_Init(NULL, NULL); 15 15 MPI_Init(NULL, NULL);
16 16
MPI_Comm_size(MPI_COMM_WORLD, &size); 17 17 MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank); 18 18 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
19 19
n=N; 20 20 n=N;
21 21
if(rank==0) 22 22 if(rank==0)
{ 23 23 {
if(argc==2) 24 24 if(argc==2)
{ 25 25 {
n = atol(argv[1]); 26 26 n = atol(argv[1]);
} 27 27 }
28 28
printf("MPI version with process = %d\n", size); 29 29 printf("MPI version with process = %d\n", size);
printf("Number of intervals: %lld\n", n); 30 30 printf("Number of intervals: %lld\n", n);
} 31 31 }
32 32
33 33
MPI_Bcast(&n, 1, MPI_LONG, 0, MPI_COMM_WORLD); 34 34 MPI_Bcast(&n, 1, MPI_LONG, 0, MPI_COMM_WORLD);
35 35
36 36
h = 1.0/n; 37 37 h = 1.0/n;
38 38
l_sum = 0.0; 39 39 l_sum = 0.0;
40 40
for (i = rank; i < n; i += size) 41 41 for (i = rank; i < n; i += size)
{ 42 42 {
x = (i + 0.5)*h; 43 43 x = (i + 0.5)*h;
lab2/factorial.c View file @ c7c188d
#include <stdio.h> 1 1 #include <stdio.h>
int main() 2
{ 3 2 int main()
int i, num, fact; 4 3 {
printf ("Enter the number: "); 5 4 int i, num, fact;
scanf ("%d", &num ); 6 5 printf ("Enter the number: ");
fact=1; 7 6 scanf ("%d", &num );
7 fact=1;
8 for (i=1; i<=num; i++)
9 fact=fact*i;
for (i=1; i<=num; i++) 8 10
fact=fact*i; 9 11 printf("The factorial of %d is %d\n",num,fact);
10
printf("The factorial of %d is %d\n",num,fact); 11
} 12
13 12 }
lab2/memory_access.c View file @ c7c188d
File was created 1
2 #include <stdlib.h>
3 #include <stdio.h>
4 #define DIM 100
5 int main(int argc, char *argv[])
6 {
7 //float *a;
8 int i;
9 float a[DIM];
10 // a = (float *) malloc( sizeof(float) * DIM );
11 for( i = 0; i < DIM; ++i) a[i] = 0.0;
12 // sup = k;
13 // k = a[i];
14 a[200] = 99.0;
15 printf("GOOD END \n");
16 // free(a);
17 return(EXIT_SUCCESS);
lab2/memory_leak.c View file @ c7c188d
File was created 1 #include <stdlib.h>
2 #include <stdio.h>
3 void f(void)
4 {
5 int* x = (int*)malloc(10 * sizeof(int));
6 x[9] = 2;
7 } // problem: memory leak -- x not freed
8 int main(int argc, char * argv[])
9 {
10 f();
11 printf("GOOD END \n");
12 return 0;
13 }
lab2/printArray.c View file @ c7c188d
1 1
#include <stdio.h> 2 2 #include <stdio.h>
3 3
void printIntArray(int *a, int n) 4
{ 5 4 void printIntArray(int *a, int n)
6 5 {
int i; 7 6
8 7 int i;
for (i=0; 1<n; i++) 9 8
a[i]=2*a[i]; 10
11 9 for (i=0; 1<n; i++)
} 12 10 a[i]=2*a[i];
13
14 11
int main() 15
{ 16 12 }