I have zero idea why this is occuring, I have looked at so many examples of pointers and arrays and I just cannot figure this out.
All I am trying to do right now is create an n by m matrix and populate it with random numbers...but all I get are null pointers (ie 0)
Code:
#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
int main(int argc, char* argv[]){
int rank;
int p;
int i, j;
double *A; //Matrix A
double *b; //Vector b
int m = atoi(argv[1]);
int n = atoi(argv[2]);
//printf("M=%d, N=%d\n", m,n); //Strictly used for testing purposes
A = malloc((n*m)*sizeof(double));
for (i=0; i<n; i++){
for(j=0; j<n; j++){
A[i*n + j] = rand() % 100;//assigns *A random numbers between 0 - 99
printf("%d\n",A[i*n +j]);
}
}
//genMatrix(n, m, A);
/*
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &p);
MPI_Finalize();
*/
return 0;
}
I even tried writing
Code:
double *A;
...
A = malloc((n*m)*sizeof(double);
...
A[0] = 5;
printf("%d", A[0]);
And this is returning 0, rather, a null pointer as well. Any help would be greatly appreciated