memory allocation, writing to file, matrix generator