-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildjson.py
More file actions
179 lines (144 loc) · 4.85 KB
/
Copy pathbuildjson.py
File metadata and controls
179 lines (144 loc) · 4.85 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import json
# Define individual code snippets
code1 = """
import numpy as np
def expensive_computation(matrix_size=1000):
# Generate two large random matrices of the specified size
A = np.random.rand(matrix_size, matrix_size)
B = np.random.rand(matrix_size, matrix_size)
# Perform matrix multiplication
result = np.dot(A, B)
return result
# Example usage
output = expensive_computation(4000) # This will multiply two 2000x2000 matrices
print("Computation completed python for 4000.")
"""
code2 = """
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
// Function to multiply two matrices
std::vector<std::vector<double>> matrixMultiply(const std::vector<std::vector<double>>& A, const std::vector<std::vector<double>>& B) {
int n = A.size();
std::vector<std::vector<double>> result(n, std::vector<double>(n, 0.0));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
result[i][j] += A[i][k] * B[k][j];
}
}
}
return result;
}
// Function to generate a random matrix
std::vector<std::vector<double>> generateRandomMatrix(int n) {
std::vector<std::vector<double>> matrix(n, std::vector<double>(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
matrix[i][j] = static_cast<double>(rand()) / RAND_MAX;
}
}
return matrix;
}
int main() {
int matrix_size = 900; // Adjust the matrix size as needed
// Seed random number generator
std::srand(std::time(0));
// Generate two large random matrices
std::vector<std::vector<double>> A = generateRandomMatrix(matrix_size);
std::vector<std::vector<double>> B = generateRandomMatrix(matrix_size);
// Perform matrix multiplication
std::vector<std::vector<double>> result = matrixMultiply(A, B);
std::cout << "Computation completed c++ for 900." << std::endl;
return 0;
}
"""
code3 = """
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
// Function to multiply two matrices
std::vector<std::vector<double>> matrixMultiply(const std::vector<std::vector<double>>& A, const std::vector<std::vector<double>>& B) {
int n = A.size();
std::vector<std::vector<double>> result(n, std::vector<double>(n, 0.0));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
result[i][j] += A[i][k] * B[k][j];
}
}
}
return result;
}
// Function to generate a random matrix
std::vector<std::vector<double>> generateRandomMatrix(int n) {
std::vector<std::vector<double>> matrix(n, std::vector<double>(n));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
matrix[i][j] = static_cast<double>(rand()) / RAND_MAX;
}
}
return matrix;
}
int main() {
int matrix_size = 700; // Adjust the matrix size as needed
// Seed random number generator
std::srand(std::time(0));
// Generate two large random matrices
std::vector<std::vector<double>> A = generateRandomMatrix(matrix_size);
std::vector<std::vector<double>> B = generateRandomMatrix(matrix_size);
// Perform matrix multiplication
std::vector<std::vector<double>> result = matrixMultiply(A, B);
std::cout << "Computation completed c++ for 700." << std::endl;
return 0;
}
"""
code4 = """
import numpy as np
def expensive_computation(matrix_size=1000):
# Generate two large random matrices of the specified size
A = np.random.rand(matrix_size, matrix_size)
B = np.random.rand(matrix_size, matrix_size)
# Perform matrix multiplication
result = np.dot(A, B)
return result
# Example usage
output = expensive_computation(3000) # This will multiply two 2000x2000 matrices
print("Computation completed python for 3000.")
"""
# Define the JSON structure
payload = {
"auth_token": "your_auth_token_here",
"machine": "cpu/gpu",
"params": {
"X_VALUE": "value1",
"Y_VALUE": "value2",
"Z_Value": "value3"
},
"gfalcon": [
{
"follow": "serial",
"language": "python",
"code": code1
},
{
"follow": "parallel",
"language": "c++",
"code": code2
},
{
"follow": "serial",
"language": "c++",
"code": code3
},
{
"follow": "parallel",
"language": "python",
"code": code4
}
]
}
# Serialize to JSON with indentation for readability
json_payload = json.dumps(payload, indent=2)