parent
51efa347c7
commit
2c7fc48298
@ -0,0 +1,39 @@ |
||||
#include "library.h" |
||||
|
||||
void *my_malloc(size_t size) { |
||||
void *p = malloc(size); |
||||
if (p == NULL) { |
||||
printf("Memory allocation unsuccessful.\n"); |
||||
exit(EXIT_FAILURE); |
||||
} |
||||
return p; |
||||
} |
||||
|
||||
|
||||
void *my_realloc(void *p, size_t size) { |
||||
void *temp = realloc(p, size); |
||||
if (temp == NULL) { |
||||
printf("Insufficient memory; can't add more items.\n"); |
||||
exit(EXIT_FAILURE); |
||||
} |
||||
return temp; |
||||
} |
||||
|
||||
|
||||
FILE *my_fopen(const char *filename, const char *mode) { |
||||
FILE *file = fopen(filename, mode); |
||||
if (file == NULL) { |
||||
printf("File %s could not be opened.\n", filename); |
||||
exit(EXIT_FAILURE); |
||||
} |
||||
return file; |
||||
} |
||||
|
||||
bool is_mpi_defined(int n) { |
||||
if (n == MPI_UNDEFINED) { |
||||
printf("MPI encountered undefined integer and terminated."); |
||||
exit(EXIT_FAILURE); |
||||
} |
||||
return true; |
||||
} |
||||
|
@ -0,0 +1,20 @@ |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <mpi.h> |
||||
#include <stdbool.h> |
||||
#include <limits.h> |
||||
|
||||
// Avoids aggresive memory reallocation at the beginning of buffer growth sequence
|
||||
#define INIT_COUNT 8 |
||||
// Optimal exponential buffer growth factor, 2 is sometimes used to
|
||||
#define GROWTH_FACTOR 1.5 |
||||
|
||||
// Macro for counting the lenght of an array
|
||||
#define COUNT(x) ((int) (sizeof(x) / sizeof(x[0]))) |
||||
|
||||
|
||||
void *my_malloc(size_t size); |
||||
void *my_realloc(void *p, size_t size); |
||||
FILE *my_fopen(const char *filename, const char *mode); |
||||
bool is_mpi_defined(int n); |
||||
|
@ -1,4 +1,4 @@ |
||||
#!/bin/bash |
||||
|
||||
mpicc -Wall "$1.c" -o "$1" |
||||
mpicc -Wall "$1.c" "library.c" -o "$1" |
||||
mpirun -v -np "$2" "$1" |
||||
|
@ -0,0 +1,10 @@ |
||||
5 |
||||
1 |
||||
8 |
||||
7 |
||||
6 |
||||
5 |
||||
4 |
||||
3 |
||||
2 |
||||
1 |
Loading…
Reference in new issue