library.c and library.h added to build for common stuff

master
Peter Babič 9 years ago
parent 51efa347c7
commit 2c7fc48298
  1. 39
      library.c
  2. 20
      library.h
  3. 2
      run
  4. BIN
      sample1_e
  5. 56
      sample1_e.c
  6. BIN
      zadanie1
  7. 55
      zadanie1.c
  8. 10
      zadanie1.in

@ -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);

2
run

@ -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"

Binary file not shown.

@ -1,23 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include <stdbool.h>
#include <limits.h>
#include "library.h"
#define INPUTFILE "sample1_e.in"
// 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);
int main(int argc, char *argv[]) {
int size, rank, slave, i, n, value, count = 0;
@ -126,40 +109,3 @@ int main(int argc, char *argv[]) {
return (0);
}
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;
}

Binary file not shown.

@ -1,23 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#include <stdbool.h>
#include <limits.h>
#include "library.h"
#define INPUTFILE "zadanie1.in"
// 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);
int main(int argc, char *argv[]) {
int size, rank, slave, i, n, value, count = 0;
@ -127,40 +110,4 @@ int main(int argc, char *argv[]) {
}
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,10 @@
5
1
8
7
6
5
4
3
2
1
Loading…
Cancel
Save