aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
blob: 92068e4d410e1a2593903b42f48b159d69e9c0a7 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"row_dispenser.c"
#include"threadet.c"
#include"input.c"


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

	mpq_t **det=NULL;
	size_t n=1;
	size_t i,j,y;
	size_t number_of_threads=1;
	char verbose=1;
	FILE *out=stdout;
	FILE *dm=NULL;
/*
 * menuing
 *
 */
	for(i=0;i<argc;++i)
	{
		if(strcmp("-i",argv[i]) == 0)
		{
			if(det!=NULL)free(det);
			++i;
			if(i == argc) 
			{
				printf("No name\n");
				return -1;
			}
			FILE *in = fopen(argv[i],"r");
			if(in == NULL)
			{
				printf("No such file\n");
				return -1;
			}
			input_det(in,&det,&n);
			fclose(in);
		}else if(strcmp("-t",argv[i]) == 0)
		{
			++i;
			if(i == argc) 
			{
				printf("No number of threads\n");
				return -1;
			}
			for(j=0;argv[i][j]!='\0';++j)
				if(argv[i][j] < '0' || argv[i][j] > '9')
				{
					printf("Number of threads format not supported\n");
					return -1;
				}
			sscanf(argv[i],"%zu",&number_of_threads);

		}else if(strcmp("-q",argv[i]) == 0)
		{
			verbose = 0;
		}else if(strcmp("-n",argv[i]) == 0)
		{
			if(det!=NULL)free(det);
			++i;
			if(i == argc) 
			{
				printf("No matrix size\n");
				return -1;
			}
			for(j=0;argv[i][j]!='\0';++j)
				if(argv[i][j] < '0' || argv[i][j] > '9')
				{
					printf("Matrix size format not supported\n");
					return -1;
				}
			sscanf(argv[i],"%zu",&n);
			random_table(&det,n);
		}else if(strcmp("-o",argv[i]) == 0)
		{
			++i;
			if(i == argc) 
			{
				printf("No name\n");
				return -1;
			}
			//fclose(out);
			out = fopen(argv[i],"w");
			if(out == NULL)
			{
				printf("No such file\n");
				return -1;
			}
		}else if(strcmp("-dm",argv[i]) == 0)
		{
			++i;
			if(i == argc) 
			{
				printf("No name\n");
				return -1;
			}
			dm = fopen(argv[i],"w");
		}

	}
	if(det==NULL)
	{
		printf("Not matrix specified\n");
		return -1;
	}
	if(dm!=NULL)
	{
		fprintf(dm,"%zu\n",n);
		for(i=0;i<n;++i)
		{
			for(j=0;j<n;++j)
			{
				gmp_fprintf(dm,"%Qi ",det[i][j]);
			}
			fprintf(dm,"\n");
		}
	}
	mpq_t *res = threadet(det,n-1,number_of_threads,verbose);
	gmp_fprintf(out,"%Qi",*res);
	free(det);
	free(res);
	return 0;
}