-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrixScalapackStore.c
101 lines (85 loc) · 2.51 KB
/
matrixScalapackStore.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <float.h>
#include "matrixScalapackStore.h"
void openScalapackStore(FILE** store, int myrow, int mycol, const char* location){
// check if the output location exists
struct stat st = {0};
if (stat(location, &st) == -1) {
mkdir(location, 0700);
}
char *file_name = malloc(sizeof(char)*(strlen(location)+300));
sprintf(file_name,"%s/blockR%dC%d.txt",location,myrow,mycol);
*store = fopen(file_name, "w");
free(file_name);
}
void readScalapackStore(FILE** store, int myrow, int mycol, const char* location){
// check if the output location exists
struct stat st = {0};
if (stat(location, &st) == -1) {
printf("ERROR: the location %s does not exists",location);
//exit(-1);
}
char *file_name = malloc(sizeof(char)*(strlen(location)+300));
sprintf(file_name,"%s/blockR%dC%d.txt",location,myrow,mycol);
*store = fopen(file_name, "r");
free(file_name);
}
int saveLocalMatrix(double* lmat,int nla, int mla, FILE* store) {
long i;
for(i = 0; i<(nla*mla) ; i++) {
fprintf(store,"%.*f\n",DBL_DIG,lmat[i]); // use all available precision cf float.h
}
return 0;
}
int readLocalMatrix(double* lmat,int nla, int mla, FILE* store) {
int i;
char * line = NULL;
size_t len = 0;
ssize_t read;
int size = nla*mla;
for(i = 0; i<size ; i++) {
if ( (read = getline(&line, &len, store)) != -1) {
lmat[i] = atof(line);
}
}
free(line);
return 0;
}
void saveMatrixDescriptor(int * desc, const char* location){
// check if the output location exists
struct stat st = {0};
if (stat(location, &st) == -1) {
mkdir(location, 0700);
}
char *file_name = malloc(sizeof(char)*(strlen(location)+300));
sprintf(file_name,"%s/descriptor.txt",location);
FILE* store = fopen(file_name, "w");
free(file_name);
int i;
for(i = 0; i<9 ; i++) {
fprintf(store,"%d\n",desc[i]);
}
fclose(store);
}
void readMatrixDescriptor(int * desc, const char* location){
char *file_name = malloc(sizeof(char)*(strlen(location)+300));
sprintf(file_name,"%s/descriptor.txt",location);
FILE* store = fopen(file_name, "r");
int i;
char * line = NULL;
size_t len = 0;
ssize_t read;
int size = 9;
for(i = 0; i<size ; i++) {
if ( (read = getline(&line, &len, store)) != -1) {
desc[i] = atoi(line);
}
}
free(line);
fclose(store);
}