summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2023-06-18 01:23:36 +0800
committerKunoiSayami <[email protected]>2023-06-18 01:23:36 +0800
commitf6a970fa86d6474e4f45055f41eb80bdac4ee756 (patch)
treecf1c8a2ee2dccd4bf9b7bc49554ff1e2d40b3ad8
parentb54ec5eca2e42fb2ac6f86ecdd47b2ec0b3b1ddf (diff)
feat(exp): Add analysis0617 script
Signed-off-by: KunoiSayami <[email protected]>
-rwxr-xr-xanalysis0617.py83
-rw-r--r--expt_0525.cu25
-rw-r--r--expt_0528.cu25
3 files changed, 109 insertions, 24 deletions
diff --git a/analysis0617.py b/analysis0617.py
new file mode 100755
index 0000000..3e62482
--- /dev/null
+++ b/analysis0617.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+import argparse
+import asyncio
+import random
+
+
+async def grab_output(p: asyncio.subprocess.Process) -> float | None:
+ out = (await p.communicate())[0].decode()
+ if p.returncode:
+ print("Error:", out)
+ return None
+ print(out.strip())
+ return float(out.rsplit(':')[-1])
+
+
+async def run_custom_exec(p_s: str, sample: int, search: int, insertion: int) -> float | None:
+ p = (await asyncio.create_subprocess_exec(p_s, str(sample), str(search), str(insertion),
+ stdout=asyncio.subprocess.PIPE))
+ await p.wait()
+ return await grab_output(p)
+
+
+async def run_exec(p_s: str, search: int, insertion: int) -> float | None:
+ p = await asyncio.create_subprocess_exec(p_s, str(search), str(insertion), stdout=asyncio.subprocess.PIPE)
+ await p.wait()
+ return await grab_output(p)
+
+
+def grab_limit(limit: str) -> tuple[int, int]:
+ if '-' in limit:
+ return tuple(map(lambda x: int(x.strip()), limit.split("-", 1)))
+ return 10, int(limit)
+
+
+async def main(matches: argparse.Namespace) -> None:
+ def pow2(n: int) -> int:
+ return 2 ** n
+
+ search_limit_low, search_limit_high = grab_limit(matches.limit)
+ limit_low, limit_high = grab_limit(matches.sample_limit)
+ total_run = 0
+ fault_run = 0
+ result = {}
+
+ for limit in range(limit_low, limit_high):
+ for search in range(search_limit_low, search_limit_high):
+ insertion = pow2(search + random.randint(1, 3))
+ search = pow2(search)
+ sample = pow2(limit) - 1
+ # print('\r', insertion, search, sample, end='')
+ if sample not in result:
+ result.update({sample: {}})
+ if search not in result[sample]:
+ result[sample].update({search: {'normal': [], 'custom': []}})
+ for _ in range(3):
+ retries = 3
+ while (normal := await run_exec(matches.exec2, search, insertion)) is None:
+ retries -= 1
+ fault_run += 1
+ if not retries:
+ break
+ total_run += 4 - retries
+ retries = 3
+ while (custom := await run_custom_exec(matches.exec1, sample, search, insertion)) is None:
+ retries -= 1
+ fault_run += 1
+ if not retries:
+ break
+ total_run += 4 - retries
+ result[sample][search]['normal'].append(normal)
+ result[sample][search]['custom'].append(custom)
+ print(fault_run, '/', total_run)
+ print(result)
+
+
+if __name__ == '__main__':
+ arg_ = argparse.ArgumentParser()
+ arg_.add_argument("exec1")
+ arg_.add_argument("exec2")
+ arg_.add_argument("sample_limit")
+ arg_.add_argument("limit")
+ parser_ = arg_.parse_args()
+ asyncio.run(main(parser_))
diff --git a/expt_0525.cu b/expt_0525.cu
index 8867cee..5af1fc0 100644
--- a/expt_0525.cu
+++ b/expt_0525.cu
@@ -655,9 +655,10 @@ int main(int argc, char **argv) {
printf("Search should smaller than insertion\n");
}
- printf("Sample: %ld, Insertion: %ld, Search: %ld\n", sample_length,
+ printf("Sample: %ld, Insertion: %ld, Search: %ld ", sample_length,
insertion_length, search_length);
+ fflush(stdout);
ReadHelper readHelper("normal_distribution.txt", sample_length,
insertion_length, 0);
readHelper.readFile();
@@ -795,16 +796,16 @@ int main(int argc, char **argv) {
// printf("%d\n", element);
#endif
#endif
- /*cudaFree(Clist);
- cudaFree(Cop2);
- cudaFree(Clevels);
- cudaFree(Cop);
- cudaFree(Citems);
- cudaFree(Cresult);
- free(pointers);
- delete [] op;
- delete [] levels;
- delete [] items;
- delete [] result;*/
+
+ cudaFree(Clist);
+ cudaFree(cudaResult);
+ cudaFree(cudaOperatorItems);
+ cudaFree(Cpointers);
+ for (int i = 0; i < insertion_length; i++) {
+ cudaFree(pointers[i]);
+ }
+ cudaFree(pointers);
+ delete[] result;
+ delete list;
return 0;
}
diff --git a/expt_0528.cu b/expt_0528.cu
index fadf3b8..cbc6c91 100644
--- a/expt_0528.cu
+++ b/expt_0528.cu
@@ -656,8 +656,9 @@ int main(int argc, char **argv) {
printf("Search should smaller than insertion\n");
}
- printf("Insertion: %ld, Search: %ld\n", insertion_length, search_length);
+ printf("Insertion: %ld, Search: %ld ", insertion_length, search_length);
+ fflush(stdout);
ReadHelper readHelper("normal_distribution.txt", 0, insertion_length, 0);
readHelper.readFile();
std::vector<key_type> _search(readHelper.population_vector.begin(),
@@ -788,16 +789,16 @@ int main(int argc, char **argv) {
// printf("%d\n", element);
#endif
#endif
- /*cudaFree(Clist);
- cudaFree(Cop2);
- cudaFree(Clevels);
- cudaFree(Cop);
- cudaFree(Citems);
- cudaFree(Cresult);
- free(pointers);
- delete [] op;
- delete [] levels;
- delete [] items;
- delete [] result;*/
+ cudaFree(Clist);
+ cudaFree(cudaResult);
+ cudaFree(cudaOperatorItems);
+ cudaFree(Cpointers);
+ for (int i = 0; i < insertion_length; i++) {
+ cudaFree(pointers[i]);
+ }
+ cudaFree(pointers);
+ delete[] result;
+ delete list;
+
return 0;
}