This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import multiprocessing as mp | |
def run(cmd): | |
with open(cmd[-1], 'w') as f: | |
return subprocess.run(cmd[:-1], stdout=f) | |
numbers = [] | |
i = 100000000 | |
for _ in range(10): | |
numbers.append(i) | |
i //= 2 | |
commands = [['./a.out', str(x), str(x) + '.txt'] for x in numbers] | |
nproc = 2 | |
pool = mp.Pool(nproc) | |
pool.map(run, commands) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
double log_factorial(int i) { | |
double ans = 0; | |
if (i <= 1) return ans; | |
while (i > 1) ans += log(i--); | |
return ans; | |
} | |
int main(int argc, char** argv) { | |
int input = atoi(argv[1]); | |
printf("log(%d!) = %f\n", input, log_factorial(input)); | |
return 0; | |
} |
No comments:
Post a Comment