diff --git a/examples/c/ADM_cancel_transfer.c b/examples/c/ADM_cancel_transfer.c index 5b2d79dadc94aecc4e71f92d4e9a824aa232931c..9669e7a02ee6710825a3a27cf929e33fef757a85 100644 --- a/examples/c/ADM_cancel_transfer.c +++ b/examples/c/ADM_cancel_transfer.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,25 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); @@ -109,7 +95,8 @@ main(int argc, char* argv[]) { "successfully\n"); cleanup: - ADM_server_destroy(server); + destroy_datasets(inputs, NINPUTS); + destroy_datasets(outputs, NOUTPUTS); exit(exit_status); } diff --git a/examples/c/ADM_connect_data_operation.c b/examples/c/ADM_connect_data_operation.c index 35ad5bdcaa202e26ef01a0ed368c042bc57c017e..6fc25c3416e4457cb60cbab57616be1487ec737a 100644 --- a/examples/c/ADM_connect_data_operation.c +++ b/examples/c/ADM_connect_data_operation.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,26 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_define_data_operation.c b/examples/c/ADM_define_data_operation.c index 5d8a5754e1e261933b51cc7ea664e5cf0c4d6f6b..ac18ff92573b38b1933d39da1f74fce3df310640 100644 --- a/examples/c/ADM_define_data_operation.c +++ b/examples/c/ADM_define_data_operation.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -44,25 +45,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_deploy_adhoc_storage.c b/examples/c/ADM_deploy_adhoc_storage.c index e74254313c8742a7d6970c7246954dbcb3e3b0a5..73a0e1accf4d5b147c663762ea4920efa438e4a2 100644 --- a/examples/c/ADM_deploy_adhoc_storage.c +++ b/examples/c/ADM_deploy_adhoc_storage.c @@ -27,9 +27,6 @@ #include #include -#define NINPUTS 10 -#define NOUTPUTS 5 - int main(int argc, char* argv[]) { diff --git a/examples/c/ADM_finalize_data_operation.c b/examples/c/ADM_finalize_data_operation.c index 4c4231f62efa701e53e0113e19bfb46347897442..a38c393a0ac47162d4b868fa36cf29af75bd94f0 100644 --- a/examples/c/ADM_finalize_data_operation.c +++ b/examples/c/ADM_finalize_data_operation.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -44,25 +45,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_get_pending_transfers.c b/examples/c/ADM_get_pending_transfers.c index 55f4b15cd4efaa2975d5ffbe4793b12a1fefce53..e089247ccf6cb9b966ac36a399a633946958b5df 100644 --- a/examples/c/ADM_get_pending_transfers.c +++ b/examples/c/ADM_get_pending_transfers.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,25 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_get_qos_constraints.c b/examples/c/ADM_get_qos_constraints.c index 03265442ed4145a903138a2d1e42f70b697c7874..88497d33c049f70a224d43af551061eee927e374 100644 --- a/examples/c/ADM_get_qos_constraints.c +++ b/examples/c/ADM_get_qos_constraints.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,26 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_get_statistics.c b/examples/c/ADM_get_statistics.c index af8a3f19cc7efe14fe25abb083c885ae7076648f..a980a2e4ff95c58cec379c58c5dbae4b3fa8819a 100644 --- a/examples/c/ADM_get_statistics.c +++ b/examples/c/ADM_get_statistics.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,25 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_get_transfer_priority.c b/examples/c/ADM_get_transfer_priority.c index e07fb07363356419c8399b1558619fccf489b746..ca088cf44bd0cc2d5c19f623811595f2c08f6938 100644 --- a/examples/c/ADM_get_transfer_priority.c +++ b/examples/c/ADM_get_transfer_priority.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,25 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_link_transfer_to_data_operation.c b/examples/c/ADM_link_transfer_to_data_operation.c index ba03648207ead7cbf23b5df3f8f99762199c1b69..cd070ef8261ad20f2109d95e34a1a505d13b67c5 100644 --- a/examples/c/ADM_link_transfer_to_data_operation.c +++ b/examples/c/ADM_link_transfer_to_data_operation.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -44,25 +45,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_register_adhoc_storage.c b/examples/c/ADM_register_adhoc_storage.c index 1469db2bb91319899d8f4228d3d22a67433bd6d5..c1740b7edf19bbd9633693c2644db451cf949175 100644 --- a/examples/c/ADM_register_adhoc_storage.c +++ b/examples/c/ADM_register_adhoc_storage.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -42,25 +43,10 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_register_job.c b/examples/c/ADM_register_job.c index 6d59e74cffab3373fbc50c35ecc003de15ba2080..72744b91490e8244f6a5f406ade0dbe12df12bce 100644 --- a/examples/c/ADM_register_job.c +++ b/examples/c/ADM_register_job.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,25 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_register_pfs_storage.c b/examples/c/ADM_register_pfs_storage.c index 66af17f4221633960d1f77d49e401b04d81746d9..9d09281f5fd6e44a2e084fcf281bc64ecf488bfb 100644 --- a/examples/c/ADM_register_pfs_storage.c +++ b/examples/c/ADM_register_pfs_storage.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -42,26 +43,10 @@ main(int argc, char* argv[]) { int exit_status = EXIT_SUCCESS; ADM_server_t server = ADM_server_create("tcp", argv[1]); - - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_job_requirements_t reqs = ADM_job_requirements_create( inputs, NINPUTS, outputs, NOUTPUTS, NULL); diff --git a/examples/c/ADM_remove_adhoc_storage.c b/examples/c/ADM_remove_adhoc_storage.c index d79d6ed7e69ea300dbf00ededb77b1704d190ebc..adb4a1f419e09ab89edb9c041eab19bccce23437 100644 --- a/examples/c/ADM_remove_adhoc_storage.c +++ b/examples/c/ADM_remove_adhoc_storage.c @@ -27,9 +27,6 @@ #include #include -#define NINPUTS 10 -#define NOUTPUTS 5 - int main(int argc, char* argv[]) { diff --git a/examples/c/ADM_remove_job.c b/examples/c/ADM_remove_job.c index 6172c890ee3876faa0b813ded94b4446214650c7..4cd38d544abc75b807cf54909e8616d64b5a076f 100644 --- a/examples/c/ADM_remove_job.c +++ b/examples/c/ADM_remove_job.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,25 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_remove_pfs_storage.c b/examples/c/ADM_remove_pfs_storage.c index cf88f7eadc327076caf1d96d87bdf04f2258cfff..a1a240d1915e8706327b329d4a99e835ffa7bc7c 100644 --- a/examples/c/ADM_remove_pfs_storage.c +++ b/examples/c/ADM_remove_pfs_storage.c @@ -27,9 +27,6 @@ #include #include -#define NINPUTS 10 -#define NOUTPUTS 5 - int main(int argc, char* argv[]) { diff --git a/examples/c/ADM_set_dataset_information.c b/examples/c/ADM_set_dataset_information.c index 7e3e3d410226a39127e899890e114102dde1ae2c..53dbe38e77e5ecf800a528d6ed287fec5667b26d 100644 --- a/examples/c/ADM_set_dataset_information.c +++ b/examples/c/ADM_set_dataset_information.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -44,25 +45,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_set_io_resources.c b/examples/c/ADM_set_io_resources.c index 307c3294309f7e273b28dd2ba6fab51d4feb5a68..785eb001f2a8a1f71527c744a043f184b28654df 100644 --- a/examples/c/ADM_set_io_resources.c +++ b/examples/c/ADM_set_io_resources.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 @@ -44,26 +45,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_set_qos_constraints.c b/examples/c/ADM_set_qos_constraints.c index 03e0423c7ac1fbfbdeae3c1b3a1227fc145f458d..61248527d4c04ef13cb83b7a210b708aeef04ab2 100644 --- a/examples/c/ADM_set_qos_constraints.c +++ b/examples/c/ADM_set_qos_constraints.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,26 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_set_transfer_priority.c b/examples/c/ADM_set_transfer_priority.c index 4993e9e7dacb9741eab11430685d43aa1bfd7643..5d08b7c80ae8efb8b90c503866fb8954ce762962 100644 --- a/examples/c/ADM_set_transfer_priority.c +++ b/examples/c/ADM_set_transfer_priority.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,26 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_transfer_dataset.c b/examples/c/ADM_transfer_dataset.c index 6f540511a117d18583654f48678bd32f5d114e06..434878a4b616983141b7dff989715dfc190f1635 100644 --- a/examples/c/ADM_transfer_dataset.c +++ b/examples/c/ADM_transfer_dataset.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,26 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_update_adhoc_storage.c b/examples/c/ADM_update_adhoc_storage.c index c5dd62b2b4b2e837f4ac595656157bdd697bd641..2b71046acc5e4d1ccf032591d470616d9407e452 100644 --- a/examples/c/ADM_update_adhoc_storage.c +++ b/examples/c/ADM_update_adhoc_storage.c @@ -27,9 +27,6 @@ #include #include -#define NINPUTS 10 -#define NOUTPUTS 5 - int main(int argc, char* argv[]) { diff --git a/examples/c/ADM_update_job.c b/examples/c/ADM_update_job.c index 62fbbd39be01ebdbef901866bea50b27d96ce6c1..da4ee588103fb49b04b4868829a79ccfebdb6326 100644 --- a/examples/c/ADM_update_job.c +++ b/examples/c/ADM_update_job.c @@ -26,6 +26,7 @@ #include #include #include +#include "common.h" #define NINPUTS 10 #define NOUTPUTS 5 @@ -43,26 +44,10 @@ main(int argc, char* argv[]) { ADM_server_t server = ADM_server_create("tcp", argv[1]); ADM_job_t job; - - ADM_dataset_t inputs[NINPUTS]; - - for(int i = 0; i < NINPUTS; ++i) { - const char* pattern = "input-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - inputs[i] = ADM_dataset_create(id); - } - - ADM_dataset_t outputs[NOUTPUTS]; - - for(int i = 0; i < NOUTPUTS; ++i) { - const char* pattern = "output-dataset-%d"; - size_t n = snprintf(NULL, 0, pattern, i); - char* id = (char*) alloca(n + 1); - snprintf(id, n + 1, pattern, i); - outputs[i] = ADM_dataset_create(id); - } + ADM_dataset_t* inputs = prepare_datasets("input-dataset-%d", NINPUTS); + assert(inputs); + ADM_dataset_t* outputs = prepare_datasets("output-dataset-%d", NOUTPUTS); + assert(outputs); ADM_adhoc_context_t ctx = ADM_adhoc_context_create( ADM_ADHOC_MODE_SEPARATE_NEW, ADM_ADHOC_ACCESS_RDWR, 42, 100, false); diff --git a/examples/c/ADM_update_pfs_storage.c b/examples/c/ADM_update_pfs_storage.c index 425206511189ed5186562844428c1e3f40c0f9ec..6acc1127e349bc51747fdbce16664d0df83ba418 100644 --- a/examples/c/ADM_update_pfs_storage.c +++ b/examples/c/ADM_update_pfs_storage.c @@ -27,9 +27,6 @@ #include #include -#define NINPUTS 10 -#define NOUTPUTS 5 - int main(int argc, char* argv[]) { diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index 6d9d2faff70af08d4ad14b577f01c090aa0730d7..dedc9f83234d46a0a15f659803c41e2e3971de61 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -31,10 +31,16 @@ list(APPEND examples_c ADM_register_job ADM_cancel_transfer ADM_connect_data_ope ADM_update_pfs_storage ADM_remove_pfs_storage) # ADM_in_situ_ops ADM_in_transit_ops not implemented + +add_library(c_examples_common STATIC) +target_sources(c_examples_common PUBLIC common.h PRIVATE common.c) +target_link_libraries(c_examples_common common::api::types) + + foreach(example IN LISTS examples_c) add_executable(${example}_c) target_sources(${example}_c PRIVATE ${example}.c) - target_link_libraries(${example}_c PUBLIC adm_iosched) + target_link_libraries(${example}_c PUBLIC adm_iosched c_examples_common) set_target_properties(${example}_c PROPERTIES OUTPUT_NAME ${example}) endforeach() diff --git a/examples/c/common.c b/examples/c/common.c new file mode 100644 index 0000000000000000000000000000000000000000..1247ff2fac9493c347f6eeb5bb0790338348d16b --- /dev/null +++ b/examples/c/common.c @@ -0,0 +1,40 @@ +#ifndef SCORD_COMMON_H +#define SCORD_COMMON_H + +#include +#include "common.h" +#include "admire_types.h" + +ADM_dataset_t* +prepare_datasets(const char* pattern, size_t n) { + + ADM_dataset_t* datasets = calloc(n, sizeof(ADM_dataset_t)); + + if(!datasets) { + return NULL; + } + + for(size_t i = 0; i < n; ++i) { + // const char* pattern = "input-dataset-%d"; + size_t len = snprintf(NULL, 0, pattern, i); + char* id = (char*) alloca(len + 1); + snprintf(id, len + 1, pattern, i); + datasets[i] = ADM_dataset_create(id); + } + + return datasets; +} + +void +destroy_datasets(ADM_dataset_t datasets[], size_t n) { + + for(size_t i = 0; i < n; ++i) { + if(datasets[i]) { + ADM_dataset_destroy(datasets[i]); + } + } + + free(datasets); +} + +#endif // SCORD_COMMON_H diff --git a/examples/c/common.h b/examples/c/common.h new file mode 100644 index 0000000000000000000000000000000000000000..3d3333534febab7c26f064447e284a8167a7ff23 --- /dev/null +++ b/examples/c/common.h @@ -0,0 +1,12 @@ +#ifndef SCORD_C_EXAMPLES_COMMON_H +#define SCORD_C_EXAMPLES_COMMON_H + +#include + +ADM_dataset_t* +prepare_datasets(const char* pattern, size_t n); + +void +destroy_datasets(ADM_dataset_t datasets[], size_t n); + +#endif // SCORD_C_EXAMPLES_COMMON_H diff --git a/examples/cxx/ADM_register_job.cpp b/examples/cxx/ADM_register_job.cpp index 8f3a149b95ee991e9cb0d75fe6acff3f76d71791..bec2e5ed8efb63f9853d2675ec00268b55ebb27e 100644 --- a/examples/cxx/ADM_register_job.cpp +++ b/examples/cxx/ADM_register_job.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright 2021, Barcelona Supercomputing Center (BSC), Spain + * Copyright 2021-2022, Barcelona Supercomputing Center (BSC), Spain * * This software was partially supported by the EuroHPC-funded project ADMIRE * (Project ID: 956748, https://www.admire-eurohpc.eu). @@ -24,6 +24,7 @@ #include #include +#include "common.hpp" #define NINPUTS 10 #define NOUTPUTS 5 @@ -39,17 +40,8 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - std::vector inputs; - inputs.reserve(NINPUTS); - for(int i = 0; i < NINPUTS; ++i) { - inputs.emplace_back(fmt::format("input-dataset-{}", i)); - } - - std::vector outputs; - outputs.reserve(NOUTPUTS); - for(int i = 0; i < NOUTPUTS; ++i) { - outputs.emplace_back(fmt::format("output-dataset-{}", i)); - } + const auto inputs = prepare_datasets("input-dataset-{}", NINPUTS); + const auto outputs = prepare_datasets("output-dataset-{}", NOUTPUTS); auto p = std::make_unique( admire::storage::type::gekkofs, "foobar", diff --git a/examples/cxx/ADM_update_job.cpp b/examples/cxx/ADM_update_job.cpp index 14846cc2b4f05c1a384f5887876365a621add949..a115691141939bb58afe4dba86dcc60e6d3e5754 100644 --- a/examples/cxx/ADM_update_job.cpp +++ b/examples/cxx/ADM_update_job.cpp @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright 2021, Barcelona Supercomputing Center (BSC), Spain + * Copyright 2021-2022, Barcelona Supercomputing Center (BSC), Spain * * This software was partially supported by the EuroHPC-funded project ADMIRE * (Project ID: 956748, https://www.admire-eurohpc.eu). @@ -24,6 +24,7 @@ #include #include +#include "common.hpp" #define NINPUTS 10 #define NOUTPUTS 5 @@ -39,17 +40,8 @@ main(int argc, char* argv[]) { admire::server server{"tcp", argv[1]}; - std::vector inputs; - inputs.reserve(NINPUTS); - for(int i = 0; i < NINPUTS; ++i) { - inputs.emplace_back(fmt::format("input-dataset-{}", i)); - } - - std::vector outputs; - outputs.reserve(NOUTPUTS); - for(int i = 0; i < NOUTPUTS; ++i) { - outputs.emplace_back(fmt::format("output-dataset-{}", i)); - } + const auto inputs = prepare_datasets("input-dataset-{}", NINPUTS); + const auto outputs = prepare_datasets("output-dataset-{}", NOUTPUTS); auto p = std::make_unique( admire::storage::type::gekkofs, "foobar", @@ -59,17 +51,9 @@ main(int argc, char* argv[]) { admire::job_requirements reqs{inputs, outputs, std::move(p)}; - std::vector new_inputs; - new_inputs.reserve(NINPUTS); - for(int i = 0; i < NINPUTS; ++i) { - new_inputs.emplace_back(fmt::format("input-new-dataset-{}", i)); - } - - std::vector new_outputs; - new_outputs.reserve(NOUTPUTS); - for(int i = 0; i < NOUTPUTS; ++i) { - new_outputs.emplace_back(fmt::format("output-new-dataset-{}", i)); - } + const auto new_inputs = prepare_datasets("input-new-dataset-{}", NINPUTS); + const auto new_outputs = + prepare_datasets("output-new-dataset-{}", NOUTPUTS); auto p2 = std::make_unique( admire::storage::type::gekkofs, "foobar", @@ -78,13 +62,11 @@ main(int argc, char* argv[]) { admire::job_requirements new_reqs{new_inputs, new_outputs, std::move(p2)}; - - ADM_return_t ret = ADM_SUCCESS; - try { [[maybe_unused]] const auto job = admire::register_job(server, reqs); - ret = admire::update_job(server, job, new_reqs); + [[maybe_unused]] ADM_return_t ret = + admire::update_job(server, job, new_reqs); fmt::print( stdout, @@ -97,10 +79,4 @@ main(int argc, char* argv[]) { e.what()); exit(EXIT_FAILURE); } - - if(ret != ADM_SUCCESS) { - fmt::print(stdout, "ADM_update_job() remote procedure not completed " - "successfully\n"); - exit(EXIT_FAILURE); - } } diff --git a/examples/cxx/CMakeLists.txt b/examples/cxx/CMakeLists.txt index e1ab0acb8624d816ce807fc4fae93670099197c4..2428d8bd8b73eda058f43b0fe6c538f651663ad1 100644 --- a/examples/cxx/CMakeLists.txt +++ b/examples/cxx/CMakeLists.txt @@ -1,5 +1,5 @@ ################################################################################ -# Copyright 2021, Barcelona Supercomputing Center (BSC), Spain # +# Copyright 2021-2022, Barcelona Supercomputing Center (BSC), Spain # # # # This software was partially supported by the EuroHPC-funded project ADMIRE # # (Project ID: 956748, https://www.admire-eurohpc.eu). # @@ -37,11 +37,15 @@ list(APPEND examples_cxx ADM_set_qos_constraints ADM_get_qos_constraints ADM_define_data_operation ADM_connect_data_operation ADM_finalize_data_operation ADM_link_transfer_to_data_operation ADM_get_statistics) +add_library(cxx_examples_common STATIC) +target_sources(cxx_examples_common PUBLIC common.hpp PRIVATE common.cpp) +target_link_libraries(cxx_examples_common common::api::types) + foreach(example IN LISTS examples_cxx) add_executable(${example}_cxx) target_sources(${example}_cxx PRIVATE ${example}.cpp) target_link_libraries(${example}_cxx - PUBLIC common::network::engine fmt::fmt adm_iosched) + PUBLIC common::network::engine fmt::fmt adm_iosched cxx_examples_common) set_target_properties(${example}_cxx PROPERTIES OUTPUT_NAME ${example}) endforeach() diff --git a/examples/cxx/common.cpp b/examples/cxx/common.cpp new file mode 100644 index 0000000000000000000000000000000000000000..83dc666ceeec90b54a89ee14734ee40f5c634249 --- /dev/null +++ b/examples/cxx/common.cpp @@ -0,0 +1,12 @@ +#include "common.hpp" + +std::vector +prepare_datasets(const std::string& pattern, size_t n) { + std::vector datasets; + datasets.reserve(n); + for(size_t i = 0; i < n; ++i) { + datasets.emplace_back(fmt::format(pattern, i)); + } + + return datasets; +} diff --git a/examples/cxx/common.hpp b/examples/cxx/common.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b64a32e77270336897f7fedcb50c6ca9977d91d5 --- /dev/null +++ b/examples/cxx/common.hpp @@ -0,0 +1,10 @@ +#ifndef SCORD_CXX_EXAMPLES_COMMON_HPP +#define SCORD_CXX_EXAMPLES_COMMON_HPP + +#include +#include + +std::vector +prepare_datasets(const std::string& pattern, size_t n); + +#endif // SCORD_CXX_EXAMPLES_COMMON_HPP