main mpi

#include
#include
#include
#include
#include
#include

int *read_dims(char *filename);
float * read_array(char *filename, int *dims, int num_dims);
void *write_to_output_file(char *filename, float *output, int *dims, int num_dims);
long int product(int *array, int n);

int main(int argc, char *argv[]){

/*Your code goes here*/

/*Here is an example of using malloc to allocate memory for an array
THIS SHOULD NOT BE THE FIRST LINE OF CODE*/
int *input_dimensions;
input_dimensions = malloc(input_num_of_dimensions*sizeof(int));
This array stores the dimensions of the input.
input_dimensions[0] would store the batch size
input_dimensions[1] would store m
input_dimensions[2] would store n
input_num_of_dimensions is how many dimensions there are, which read_dims() returns at position [0].
In the case for the input matrix, it has 3 dimensions. So memory is allocated for 3 integers(an array of 3 elements)
When allocating memory, it must be freed at the end of the program. e.g. free(input_dimensions);

/*Code for reading and writing to the files*/

/*Gets the dimensions of the matrices. This will return a 1d array of 4 elements [0] = number of dimensions [1] = batch [2] = m [3] = n*/
int *read_dims(char *filename) {
FILE *file = fopen(filename,”r”);

if(file == NULL) {
printf(“Unable to open file: %s”, filename);
return NULL;

char firstline[500];
fgets(firstline, 500, file);

int line_length = strlen(firstline);

int num_dims = 0;

for(i=0; i