diff --git a/README.md b/README.md index 4b15145fde3434387e3e886e5cefb3e3c75e4996..31774abfb6c8ec918aa7bec8ddcdec014053a2c0 100644 --- a/README.md +++ b/README.md @@ -2,93 +2,22 @@ contact: francesco.tomba@phd.units.it +# USAGE +Clone the repository and compile with `make` +The compilation process produces an executable called `main`, run it with `mpirun` +The suggestion is to run it with one mpi task per socket. + - -h --help show help message + - -i --in-data *(required)* path of the input file + - -t --in-type *(required)* datatype of the input file, allowed choices `f32`, `f64` + - -d --in-dims *(required)* number of dimensions of the data file, dadp expects something of the form N x d where N is inferred from the lenght of the data file + - -o --out-data *(optional)* output path for the data, the datafile is shuffled between mpi tasks and datapoints are ordered default is `out_data` + - -a --out-assignment *(optional)* output path for the cluster assignment output ranges [0 ... Nc - 1] for core points halo points have indices [-Nc ... -1] conversion of idx for an halo point is `cluster_idx = -halo_idx - 1` + +# TODO + + - [x] ~~arugment parser~~ + - [ ] prettify overall stdout + - [ ] H1: implementation of lock free centers elimination + - [ ] kdtree: implement slim heap + - [ ] kdtree: optimization an profiling -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://www.ict.inaf.it/gitlab/luca.tornatore/dadp.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://www.ict.inaf.it/gitlab/luca.tornatore/dadp/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/src/common/common.c b/src/common/common.c index e7b95923ea941490b752cb3fda71e948beea5077..71f57f58f39e30ee4148e09479826868a77b5c00 100644 --- a/src/common/common.c +++ b/src/common/common.c @@ -19,6 +19,8 @@ void get_context(global_context_t* ctx) ctx -> rank_idx_start = (int*)malloc(ctx -> world_size * sizeof(int)); ctx -> local_datapoints = NULL; ctx -> __local_heap_buffers = NULL; + ctx -> input_data_in_float32 = -1; + ctx -> dims = 0; } void get_dataset_diagnostics(global_context_t* ctx, float_t* data) @@ -296,7 +298,7 @@ float_t* read_data_file(global_context_t *ctx, const char *fname, const idx_t nd FILE *f = fopen(fname, "r"); if (!f) { - printf("Nope\n"); + fprintf(stderr,"Cannot open file %s\n", fname); exit(1); } fseek(f, 0, SEEK_END); diff --git a/src/common/common.h b/src/common/common.h index b62bd6a3890c8a982a0a56a68c409746c6efecd9..c1df3b6d6a66b521fa574e853d70739a30879d1a 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -21,6 +21,7 @@ //#define PRINT_H1_CLUSTER_ASSIGN_COMPLETION //#define PRINT_ORDERED_BUFFER +#define DEFAULT_STR_LEN 200 #define MAX(A,B) ((A) > (B) ? (A) : (B)) #define MIN(A,B) ((A) < (B) ? (A) : (B)) @@ -159,6 +160,10 @@ typedef struct global_context_t int* rank_n_points; //processor name heap_node* __local_heap_buffers; //buffer that stores nearest neighbors MPI_Comm mpi_communicator; //mpi communicator + char input_data_file[DEFAULT_STR_LEN]; + int input_data_in_float32; + char output_assignment_file[DEFAULT_STR_LEN]; + char output_data_file[DEFAULT_STR_LEN]; } global_context_t; typedef struct pointset_t diff --git a/src/main/main.c b/src/main/main.c index c17df283196bb2f780e2eecd561691635672bdd6..ac205230c4ad2b4e51390e9584bbbbf00e09749b 100644 --- a/src/main/main.c +++ b/src/main/main.c @@ -4,13 +4,13 @@ #include "../common/common.h" #include "../tree/tree.h" #include "../adp/adp.h" -#include <argp.h> +#include <unistd.h> +#include <getopt.h> #ifdef AMONRA #pragma message "Hi, you are on amonra" #define OUT_CLUSTER_ASSIGN "/beegfs/ftomba/phd/results/final_assignment.npy" - #define OUT_HALO_FLAGS "/beegfs/ftomba/phd/results/halo_flags.npy" #define OUT_DATA "/beegfs/ftomba/phd/results/ordered_data.npy" #endif @@ -36,6 +36,91 @@ #define THREAD_LEVEL MPI_THREAD_MULTIPLE #endif + +struct option long_options[] = +{ + {"in-data" , required_argument, 0, 'i'}, + {"in-dtype", required_argument, 0, 't'}, + {"in-dims" , required_argument, 0, 'd'}, + {"out-data", optional_argument, 0, 'o'}, + {"out-assignment", optional_argument, 0, 'a'}, + {"help", optional_argument, 0, 'h'}, + {0, 0, 0, 0} +}; + +const char* help = "Distributed Advanced Density Peak\n"\ + " -h --help show this message\n"\ + " -i --in-data (required) path of the input file\n"\ + " -t --in-type (required) datatype of the input file, allowed choices `f32`, `f64`\n"\ + " -d --in-dims (required) number of dimensions of the data file, dadp expects something\n"\ + " of the form N x d where N is inferred from the lenght of the\n"\ + " data file\n"\ + " -o --out-data (optional) output path for the data, the datafile is shuffled between\n"\ + " mpi tasks and datapoints are ordered default is `out_data` \n"\ + " -a --out-assignment (optional) output path for the cluster assignment output ranges [0 ... Nc - 1]\n"\ + " for core points halo points have indices [-Nc ... -1] conversion\n"\ + " of idx for an halo point is cluster_idx = -halo_idx - 1\n"; + +void parse_args(global_context_t* ctx, int argc, char** argv) +{ + int err = 0; + int opt; + int input_file_set = 0; + int input_type_set = 0; + snprintf(ctx -> output_assignment_file, DEFAULT_STR_LEN, "%s", OUT_CLUSTER_ASSIGN); + snprintf(ctx -> output_data_file, DEFAULT_STR_LEN, "%s", OUT_DATA); + + while((opt = getopt_long(argc, argv, "i:t:d:o:a:h", long_options, NULL)) != -1) + { + switch(opt) + { + case 'i': + strncpy(ctx -> input_data_file, optarg, DEFAULT_STR_LEN); + input_file_set = 1; + break; + case 't': + ctx -> input_data_in_float32 = -1; + if(strncmp(optarg, "f32", DEFAULT_STR_LEN) == 0) ctx -> input_data_in_float32 = MY_TRUE; + if(strncmp(optarg, "f64", DEFAULT_STR_LEN) == 0) ctx -> input_data_in_float32 = MY_FALSE; + if(ctx -> input_data_in_float32 == -1) + { + fprintf(stderr, "Invalid option of datatype, allowed are f32, f64\n"); + exit(1); + } + input_type_set = 1; + break; + case 'd': + ctx -> dims = atoi(optarg); + if(ctx -> dims < 0) + { + fprintf(stderr, "Invaild number of dimensions\n"); + exit(1); + } + break; + case 'o': + strncpy(ctx -> output_data_file, optarg, DEFAULT_STR_LEN); + break; + case 'a': + strncpy(ctx -> output_assignment_file, optarg, DEFAULT_STR_LEN); + break; + case 'h': + mpi_printf(ctx, "%s\n", help); + MPI_Finalize(); + exit(0); + default: + mpi_printf(ctx, "%s\n", help); + MPI_Finalize(); + exit(0); + break; + } + } + + if(ctx -> dims == 0){mpi_printf(ctx,"Please provide number of dimensions with -d\n"); ++err;}; + if(!input_file_set){mpi_printf(ctx,"Please provide input file with -i\n"); ++err;}; + if(!input_type_set){mpi_printf(ctx,"Please provide input type with -t\n"); ++err;}; + if(err){MPI_Finalize(); exit(1);}; +} + int main(int argc, char** argv) { #if defined (_OPENMP) int mpi_provided_thread_level; @@ -95,6 +180,10 @@ int main(int argc, char** argv) { float_t* data; + //parse command line + + parse_args(&ctx, argc, argv); + printf("DIO\n"); /* * Generate a random matrix of lenght of some kind @@ -144,6 +233,8 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) TIME_START; if (ctx->mpi_rank == 0) { + data = read_data_file(ctx,ctx -> input_data_file, ctx -> dims, ctx -> input_data_in_float32); + //data = read_data_file(ctx, "../norm_data/50_blobs_more_var.npy", MY_TRUE); //ctx->dims = 2; //data = read_data_file(ctx, "../norm_data/blobs_small.npy", MY_FALSE); @@ -167,7 +258,7 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) // data = read_data_file(ctx,"../norm_data/std_g2980844_091_0000",5,MY_TRUE); /* 1M points ca.*/ - data = read_data_file(ctx,"../norm_data/std_LR_091_0001",5,MY_TRUE); + //data = read_data_file(ctx,"../norm_data/std_LR_091_0001",5,MY_TRUE); /* BOX */ // data = read_data_file(ctx,"../norm_data/std_Box_256_30_092_0000",MY_TRUE); @@ -184,7 +275,7 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) //data = read_data_file(ctx,"../norm_data/std_g1212639_091_0001",MY_TRUE); //for weak scalability - ctx->n_points = ctx->n_points / 4; + //ctx->n_points = ctx->n_points / 4; //ctx->n_points = (ctx->n_points / 32) * ctx -> world_size; get_dataset_diagnostics(ctx, data); @@ -364,16 +455,16 @@ void simulate_master_read_and_scatter(int dims, size_t n, global_context_t *ctx) if(ctx -> world_size <= 6) { - big_ordered_buffer_to_file(ctx, cl, sizeof(int), ctx -> local_n_points, OUT_CLUSTER_ASSIGN); - big_ordered_buffer_to_file(ctx, ctx -> local_data, sizeof(double), ctx -> local_n_points * ctx -> dims, OUT_DATA); + big_ordered_buffer_to_file(ctx, cl, sizeof(int), ctx -> local_n_points, ctx -> output_assignment_file); + big_ordered_buffer_to_file(ctx, ctx -> local_data, sizeof(double), ctx -> local_n_points * ctx -> dims, ctx -> output_data_file); free(cl); } else { - distributed_buffer_to_file(ctx, cl, sizeof(int), ctx -> local_n_points, OUT_CLUSTER_ASSIGN); - distributed_buffer_to_file(ctx, ctx -> local_data, sizeof(double), ctx -> local_n_points * ctx -> dims, OUT_DATA); + distributed_buffer_to_file(ctx, cl, sizeof(int), ctx -> local_n_points, ctx -> output_assignment_file); + distributed_buffer_to_file(ctx, ctx -> local_data, sizeof(double), ctx -> local_n_points * ctx -> dims, ctx -> output_data_file); free(cl);