int long_test() { grpc_error_t ret; long a[N], b[N]; int success = 1; int i; int handleInitialized = 0; ret = grpc_function_handle_default(&handles, MODULE_NAME "/long_test"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); success = 0; goto finalize; } handleInitialized = 1; for (i = 0; i < N; i++) { a[i] = i; b[i] = 0; } ret = grpc_call(&handles, (long)N, a, b); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); success = 0; goto finalize; } for (i = 0; i < N; i++) { if (a[i] != b[i]) { success = 0; if (verbose) { printf("long_test: a[%d](%ld) != b[%d](%ld)\n", i, a[i], i, b[i]); } } } finalize: if (handleInitialized != 0) { ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); success = 0; } handleInitialized = 0; } return success; }
int string_test() { grpc_error_t ret; char *buffer = NULL; char teststring[TEST_STR_LENGTH]; int i; int success = 1; int handleInitialized = 0; ret = grpc_function_handle_default(&handles, MODULE_NAME "/string_test"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); success = 0; goto finalize; } handleInitialized = 1; for (i = 0; i < TEST_STR_LENGTH -1; i++) { *(teststring + i) = (i % 10) + '0'; } *(teststring + i) = '\0'; ret = grpc_call(&handles, teststring, &buffer); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); success = 0; goto finalize; } if (strcmp(teststring, buffer) != 0) { if (verbose) { printf("%s != %s\n", teststring, buffer); } success = 0; } finalize: if (handleInitialized != 0) { ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); success = 0; } handleInitialized = 0; } /* buffer was allocated in grpc_call() by malloc() */ free(buffer); return success; }
int callback_multi_test() { grpc_error_t ret; double a[N][N], b[N][N]; int i, j; int rVal = 1; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { a[i][j] = i * N + j; b[i][j] = 0.0; } } ret = grpc_function_handle_default(&handles, MODULE_NAME "/callback_multi_test"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); rVal = 0; goto end; } ret = grpc_call(&handles, N, a, b, callback_return_func, callback_return_func); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); rVal = 0; } ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); rVal = 0; } if (rVal != 0) { for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { if (a[i][j] != b[i][j]) { rVal = 0; goto end; } } } } end: return rVal; }
int callback_string_test() { grpc_error_t ret; char *strings[] = {"caller0","caller1","caller2","caller3","caller4"}; char string[64]= ""; int i; int rVal = 1; for (i = 0; i < 5; i++) { strcat(string, strings[i]); } ret = grpc_function_handle_default(&handles, MODULE_NAME "/callbackstr"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); rVal = 0; goto end; } ret = grpc_call(&handles, strings, callbackstring_func); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); rVal = 0; } ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); rVal = 0; } if (verbose) { printf("\ncallbacked = '%s'", callbacked); } if (verbose) { printf("\nfrontend = '%s'\n", string); } if (rVal != 0) { if (strcmp(callbacked, string) != 0) { rVal = 0; } } end: return rVal; }
int callback_test() { grpc_error_t ret; double initial = 100.0, lsum = 0.0; int times = 1; int rVal = 1; sum = 0.0; ret = grpc_function_handle_default(&handles, MODULE_NAME "/callback_test"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); rVal = 0; goto end; } ret = grpc_call(&handles, initial, times, callback_func); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); rVal = 0; } ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); rVal = 0; } if (rVal != 0) { int i; double d = 0.0; for (i = 0; i < times; i++) { d += initial; lsum += d; } if (sum != lsum) { if (verbose) { printf("sum = %f(should be %f)\n", sum, lsum); } rVal = 0; } } end: return rVal; }
/* * Copy from inout-file to out-file and from in-file to inout-file. */ int main(int argc, char *argv[]) { grpc_error_t ret; if (argc < 5) { fprintf(stderr, "Usage: %s config in-file inout-file out-file\n", argv[0]); exit(2); } ret = grpc_initialize(argv[1]); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_initialize() error. (%s)\n", grpc_error_string(ret)); exit(2); } ret = grpc_function_handle_default(&handles, MODULE_NAME "/filename_test"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); exit(2); } ret = grpc_call(&handles, argv[2], argv[3], argv[4]); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); exit(2); } ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); exit(2); } ret = grpc_finalize(); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_finalize() error. (%s)\n", grpc_error_string(ret)); exit(2); } return 0; }
/* * destructor */ rpc_cpi_impl::~rpc_cpi_impl (void) { grpc_error_t err; std::cout << "Destructing the RPC handle" << std::endl; err = grpc_function_handle_destruct(&rpc_handle); if (err != GRPC_NO_ERROR) { SAGA_ADAPTOR_THROW ("Failed to invoke grpc_function_handle_destruct().", saga::NoSuccess); } std::cout << "Finalizing" << std::endl; err = grpc_finalize(); if (err != GRPC_NO_ERROR) { SAGA_ADAPTOR_THROW ("Failed to invoke grpc_finalize().", saga::NoSuccess); } }
int string_array_test() { static const char *in[] = { "This is a test for array of string.\n", "Hello, World", "Sun Mon Tue Wed Thu Fri Sat", "ls -- list directory contents", "All tests were successful.", }; static const char *answer[] = { "Were all tests successful?", "Sun Mon Tue Wed Thu Fri Sat", "Good morning", }; char *out[3] = {NULL, NULL, NULL}; grpc_error_t ret; int success = 1; int handleInitialized = 0; ret = grpc_function_handle_default(&handles, MODULE_NAME "/string_array_test"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); success = 0; goto finalize; } handleInitialized = 1; ret = grpc_call(&handles, in, out); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); success = 0; goto finalize; } if (strcmp(out[0], answer[0]) != 0) { if (verbose) { printf("%s != %s\n", out[0], answer[0]); } success = 0; } if (strcmp(out[1], answer[1]) != 0) { if (verbose) { printf("%s != %s\n", out[1], answer[1]); } success = 0; } if (strcmp(out[2], answer[2]) != 0) { if (verbose) { printf("%s != %s\n", out[2], answer[2]); } success = 0; } finalize: /* out was allocated in grpc_call() by malloc() */ free(out[0]); free(out[1]); free(out[2]); if (handleInitialized != 0) { ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); success = 0; } handleInitialized = 0; } return 1; }
int dcomplex_test() { grpc_error_t ret; dcomplex scalarIn, scalarOut; dcomplex a[N], b[N]; int success = 1; int i; int handleInitialized = 0; scalarIn.r = 1.0; scalarIn.i = 2.0; scalarOut.r = 0.0; scalarOut.i = 0.0; for (i = 0; i < N; i++) { a[i].r = i; a[i].i = i + 0.1; b[i].r = 0; b[i].i = 0; } ret = grpc_function_handle_default(&handles, MODULE_NAME "/dcomplex_test"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); success = 0; goto finalize; } handleInitialized = 1; ret = grpc_call(&handles, N, scalarIn, a, &scalarOut, b); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); success = 0; goto finalize; } if ((scalarOut.r != scalarIn.r) || (scalarOut.i != scalarIn.i)) { success = 0; if (verbose) { printf("dcomplex_test: scalarIn(%f, %f) != scalarOut(%f, %f)\n", scalarIn.r, scalarIn.i, scalarOut.r, scalarOut.i); } } for (i = 0; i < N; i++) { if (!compare_double(a[i].r, b[i].r) || !compare_double(a[i].i, b[i].i)) { success = 0; if (verbose) { printf("dcomplex_test: a[%d](%f, %f) != b[%d](%f, %f)\n", i, a[i].r, a[i].i, i, b[i].r, b[i].i); } } } finalize: if (handleInitialized != 0) { ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); success = 0; } handleInitialized = 0; } return success; }
int double_test() { grpc_error_t ret; double scalarIn, scalarOut; double a[N], b[N]; int success = 1; int i; int handleInitialized = 0; ret = grpc_function_handle_default(&handles, MODULE_NAME "/double_test"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); success = 0; goto finalize; } handleInitialized = 1; scalarIn = 1.0; scalarOut = 0.0; for (i = 0; i < N; i++) { a[i] = i; b[i] = 0; } ret = grpc_call(&handles, N, scalarIn, a, &scalarOut, b); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); success = 0; goto finalize; } if (scalarOut != scalarIn) { success = 0; if (verbose) { printf("double_test: scalarIn(%f) != scalarOut(%f)\n", scalarIn, scalarOut); } } for (i = 0; i < N; i++) { if (!compare_double(a[i],b[i])) { success = 0; if (verbose) { printf("double_test: a[%d](%f) != b[%d](%f)\n", i, a[i], i, b[i]); } } } finalize: if (handleInitialized != 0) { ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); success = 0; } handleInitialized = 0; } return success; }
int cancel_test() { grpc_sessionid_t id; grpc_error_t ret; int rVal = 1; int handleInitialized = 0; ret = grpc_function_handle_default(&handles[0], MODULE_NAME "/cancel"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); rVal = 0; goto finalize; } handleInitialized = 1; ret = grpc_call_async(&handles[0], &id); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call_async() error. (%s)\n", grpc_error_string(ret)); rVal = 0; goto finalize; } ret = grpc_cancel(id); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_cancel() error. (%s)\n", grpc_error_string(ret)); rVal = 0; goto finalize; } ret = grpc_wait(id); if (ret != GRPC_SESSION_FAILED) { fprintf(stderr, "grpc_wait() error. (%s)\n", grpc_error_string(ret)); if (verbose) { printf("session %d was finished successfully...\n", id); } rVal = 0; goto finalize; } if (grpc_get_error(id) == GRPC_CANCELED_NP) { if (verbose) { printf("session %d is canceled\n", id); } } else { rVal = 0; if (verbose) { printf("session %d is not canceled: something went wrong.\n", id); } } finalize: if (handleInitialized != 0) { ret = grpc_function_handle_destruct(&handles[0]); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); rVal = 0; } handleInitialized = 0; } return rVal; }
int main(int argc, char *argv[]) { grpc_function_handle_t handle; grpc_sessionid_t id; grpc_error_t result = GRPC_NO_ERROR; char *host = NULL; long times, answer; if (argc != 3){ fprintf(stderr, "USAGE: %s TIMES HOSTNAME\n", argv[0]); exit(2); } times = atol(argv[1]); host = argv[2]; /* Initialize */ result = grpc_initialize(config_file); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_initialize() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Initialize Function handles */ result = grpc_function_handle_init(&handle, host, func_name); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_init() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Asynchronous call */ result = grpc_call_async(&handle, &id, times, &answer); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_call_async() error. (%s)\n", grpc_error_string(result)); exit(2); } /* wait for session */ result = grpc_wait_all(); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_wait_all() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Destruct Function handles */ result = grpc_function_handle_destruct(&handle); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Compute and display pi. */ printf("PI = %f\n", 4.0 * ((double)answer / times)); /* Finalize */ result = grpc_finalize(); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_finalize() error. (%s)\n", grpc_error_string(result)); exit(2); } return 0; }
int cancel_all_test() { grpc_sessionid_t id[M]; grpc_error_t ret; int i; int nInit = 0; int nCall = 0; int rVal = 1; for (nInit = 0; nInit < M; nInit++) { ret = grpc_function_handle_default(&handles[nInit], MODULE_NAME "/cancel"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); rVal = 0; goto finalize; } } for (nCall = 0; nCall < M; nCall++) { ret = grpc_call_async(&handles[nCall], &id[nCall]); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call_async() error. (%s)\n", grpc_error_string(ret)); rVal = 0; break; } } ret = grpc_cancel_all(); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_cancel() error. (%s)\n", grpc_error_string(ret)); rVal = 0; } ret = grpc_wait_all(); if (ret != GRPC_SESSION_FAILED) { fprintf(stderr, "grpc_wait_all() error. (%s)\n", grpc_error_string(ret)); rVal = 0; } for (i = 0; i < nCall; i++) { if (grpc_get_error(id[i]) == GRPC_CANCELED_NP) { if (verbose) { printf("session %d is canceled\n", id[i]); } } else { rVal = 0; if (verbose) { printf("session %d is not canceled: something went wrong.\n", id[i]); } } } finalize: for (i = 0; i < nInit; i++) { ret = grpc_function_handle_destruct(&handles[i]); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); rVal = 0; } } return rVal; }
int main(int argc, char *argv[]) { grpc_function_handle_t *handles; grpc_sessionid_t *ids = NULL, id; grpc_error_t result; char **hosts = NULL; double param1[DEF_SCALAR][DEF_SCALAR]; double param2[DEF_SCALAR][DEF_SCALAR]; double *param3; double wk1, wk2; int n; int index, base; int i, j, k; if (argc < 2) { fprintf(stderr, "USAGE: %s HOSTNAME.\n", argv[0]); fprintf(stderr, "USAGE: %s HOSTNAME1 HOSTNAME2...\n", argv[0]); exit(2); } n = argc - 1; hosts = (char **)malloc(sizeof(char *) * n); if (hosts == NULL) { fprintf(stderr, "malloc: Can't allocate the storage for hostname.\n"); exit(2); } for (i = 1, j = 0; j < n; i++, j++) { hosts[j] = NULL; hosts[j] = strdup(argv[i]); if (*hosts == NULL) { fprintf(stderr, "strdup: Can't allocate the storage for hostname.\n"); exit(2); } } handles = (grpc_function_handle_t *)malloc( sizeof(grpc_function_handle_t) * n); if (handles == NULL) { fprintf(stderr, "malloc: Can't allocate the storage for handles.\n"); exit(2); } ids = (grpc_sessionid_t *)malloc(sizeof(grpc_sessionid_t) * n); if (ids == NULL) { fprintf(stderr, "malloc: Can't allocate the storage.\n"); exit(2); } param3 = (double *)malloc(sizeof(double) * n * DEF_SCALAR * DEF_SCALAR); if (param3 == NULL) { fprintf(stderr, "malloc: Can't allocate the storage.\n"); exit(2); } /* Initialize the parameter */ for (j = 0, wk1 = 1.0, wk2 = 500.0; j < DEF_SCALAR; j++) { for (k = 0; k < DEF_SCALAR; k++) { param1[j][k] = wk1++; param2[j][k] = wk2++; } } for (i = 0; i < (n * DEF_SCALAR * DEF_SCALAR); i++) { param3[i] = 0.0; } for (i = 0; i < DEF_SCALAR; i++) { for (j = 0; j < DEF_SCALAR; j++) { fprintf(stdout, "%f ", param1[i][j]); } fprintf(stdout, "\n"); } fprintf(stdout, "\n"); for (i = 0; i < DEF_SCALAR; i++) { for (j = 0; j < DEF_SCALAR; j++) { fprintf(stdout, "%f ", param2[i][j]); } fprintf(stdout, "\n"); } fprintf(stdout, "\n"); /* Initialize */ result = grpc_initialize(config_file); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_initialize() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Initialize Function handles */ for (i = 0; i < n; i++) { result = grpc_function_handle_init(&handles[i], hosts[i], func_name); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_init() error. (%s)\n", grpc_error_string(result)); exit(2); } } /* Asynchronous call */ for (i = 0; i < n; i++) { result = grpc_call_async(&handles[i], &ids[i], DEF_SCALAR, param1, param2, param3 + (i * DEF_SCALAR * DEF_SCALAR)); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_call_async() error. (%s)\n", grpc_error_string(result)); exit(2); } } for (k = 0; k < n; k++) { /* Wait any session */ result = grpc_wait_any(&id); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_wait_any() error. (%s)\n", grpc_error_string(result)); exit(2); } fprintf(stdout, "got Session ID = %d\n", id); for (index = 0; index < n; index++) { if (ids[index] == id) { break; } } fprintf(stdout, "index = %d, ID = %d\n", index, id); base = index * DEF_SCALAR * DEF_SCALAR; for (i = 0; i < DEF_SCALAR; i++) { for (j = 0; j < DEF_SCALAR; j++) { fprintf(stdout, "%f ", param3[base + (i * DEF_SCALAR) + j]); } fprintf(stdout, "\n"); } fprintf(stdout, "\n"); } /* Destruct Function handles */ for (i = 0; i < n; i++) { result = grpc_function_handle_destruct(&handles[i]); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(result)); exit(2); } } /* Finalize */ result = grpc_finalize(); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_finalize() error. (%s)\n", grpc_error_string(result)); exit(2); } for (i = 0; i < n; i++) { free(hosts[i]); } free(hosts); free(handles); free(ids); free(param3); return 0; }
int main(int argc, char *argv[]) { grpc_function_handle_t *handles; grpc_sessionid_t *ids = NULL; grpc_error_t result = GRPC_NO_ERROR; char **hosts = NULL; double pi; long *count = NULL; long times, sum; int n; int i, j; if (argc < 3){ fprintf(stderr, "USAGE: %s TIMES HOSTNAME\n", argv[0]); fprintf(stderr, "USAGE: %s TIMES HOSTNAME1 HOSTANME2...\n", argv[0]); exit(2); } n = argc - 2; hosts = (char **)malloc(sizeof(char *) * n); if (hosts == NULL) { fprintf(stderr, "malloc: Can't allocate the storage for hostname.\n"); exit(2); } for (i = 2, j = 0; j < n; i++, j++) { hosts[j] = NULL; hosts[j] = strdup(argv[i]); if (*hosts == NULL) { fprintf(stderr, "strdup: Can't allocate the storage for hostname.\n"); exit(2); } } times = atol(argv[1]) / n; handles = (grpc_function_handle_t *)malloc( sizeof(grpc_function_handle_t) * n); if (handles == NULL) { fprintf(stderr, "malloc: Can't allocate the storage for handles.\n"); exit(2); } count = (long *)malloc(sizeof(long) * n); if (count == NULL) { fprintf(stderr, "malloc: Can't allocate the storage.\n"); exit(2); } ids = (grpc_sessionid_t *)malloc(sizeof(grpc_sessionid_t) * n); if (ids == NULL) { fprintf(stderr, "malloc: Can't allocate the storage.\n"); exit(2); } /* Initialize */ result = grpc_initialize(config_file); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_initialize() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Initialize Function handles */ for (i = 0; i < n; i++) { result = grpc_function_handle_init(&handles[i], hosts[i], func_name); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_init() error. (%s)\n", grpc_error_string(result)); exit(2); } } /* Asynchronous call */ for (i = 0; i < n; i++) { result = grpc_call_async(&handles[i], &ids[i], i, times, &count[i]); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_call_async() error. (%s)\n", grpc_error_string(result)); exit(2); } } /* Asynchronous call */ result = grpc_wait_all(); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_wait_all() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Destruct Function handles */ for (i = 0; i < n; i++) { result = grpc_function_handle_destruct(&handles[i]); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(result)); exit(2); } } /* Compute and display pi. */ for (i = 0, sum = 0; i < n; i++) { sum += count[i]; } pi = 4.0 * (sum / ((double) times * n)); printf("PI = %f\n", pi); /* Finalize */ result = grpc_finalize(); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_finalize() error. (%s)\n", grpc_error_string(result)); exit(2); } for (i = 0; i < n; i++) { free(hosts[i]); } free(hosts); free(handles); free(count); free(ids); return 0; }
int main(int argc, char *argv[]) { grpc_function_handle_t *handle; grpc_sessionid_t *id = NULL; grpc_error_t result = GRPC_NO_ERROR; char *host = NULL; int n; double scalarIn; double scalarOut; double *arrayIn; double *arrayOut; int i; int mismatchCount = 0; if (argc < 3){ fprintf(stderr, "USAGE: %s HOSTNAME No_of_CPUs\n", argv[0]); exit(2); } host = strdup(argv[1]); n = atoi(argv[2]); /* prepare arg data */ arrayIn = (double*)malloc(sizeof(double)*n); arrayOut = (double*)malloc(sizeof(double)*n); scalarIn = 1; for (i = 0; i < n; i++){ arrayIn[i] = (double)i; } handle = (grpc_function_handle_t *)malloc(sizeof(grpc_function_handle_t)); if (handle == NULL) { fprintf(stderr, "malloc: Can't allocate the storage for handles.\n"); exit(2); } id = (grpc_sessionid_t *)malloc(sizeof(grpc_sessionid_t)); if (id == NULL) { fprintf(stderr, "malloc: Can't allocate the storage.\n"); exit(2); } /* Initialize */ result = grpc_initialize(config_file); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_initialize() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Initialize Function handles */ result = grpc_function_handle_init(handle, host, func_name); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_init() error. (%s)\n", grpc_error_string(result)); exit(2); } printf("async call start: %s\n", host); /* Asynchronous call */ result = grpc_call_async(handle, id, n, scalarIn, &scalarOut, arrayIn, arrayOut); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_call_async() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Asynchronous call wait*/ result = grpc_wait_all(); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_wait_all() error. (%s)\n", grpc_error_string(result)); exit(2); } printf("wait_all end\n"); /* Destruct Function handles */ result = grpc_function_handle_destruct(handle); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(result)); exit(2); } printf("destruct handle end\n"); /* Check Result */ if(scalarIn != scalarOut){ printf("Result is NOT correct: scalarIn(%f) != scalarOut(%f)\n", scalarIn, scalarOut); } else{ printf("Result is correct: scalarIn(%f) == scalarOut(%f)\n", scalarIn, scalarOut); } for (i = 0; i < n; i++) { if(arrayIn[i] != arrayOut[i]){ printf("Result is NOT correct: arrayIn(%f) != arrayOut(%f) at %d\n", arrayIn[i], arrayOut[i], i); mismatchCount++; } } if(mismatchCount == 0){ printf("Result is correct for all array args\n"); } /* Finalize */ result = grpc_finalize(); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_finalize() error. (%s)\n", grpc_error_string(result)); exit(2); } free(host); free(handle); free(id); return 0; }
/* * Copy from inout-file to out-file and from in-file to inout-file. */ int main(int argc, char *argv[]) { grpc_error_t ret; int result; char *conf, *array_size_str, *end; int array_size; char **in_file_array, **inout_file_array, **out_file_array; char *in_file, *inout_file, *out_file; if (argc < 6) { fprintf(stderr, "Usage: %s config count in-file inout-file out-file\n", argv[0]); exit(2); } conf = argv[1]; array_size_str = argv[2]; in_file = argv[3]; inout_file = argv[4]; out_file = argv[5]; ret = grpc_initialize(conf); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_initialize() error. (%s)\n", grpc_error_string(ret)); exit(2); } array_size = strtol(array_size_str, &end, 0); if (*end != '\0') { fprintf(stderr, "Argument \"%s\" is not digit.\n", array_size_str); exit(1); } else if (array_size < 1){ fprintf(stderr, "array_size %d < 1 (min)\n", array_size); exit(1); } result = create_file_names(array_size, in_file, inout_file, out_file, &in_file_array, &inout_file_array, &out_file_array); if (result == 0) { fprintf(stderr, "creating filenames failed\n"); exit(1); } result = check_files(array_size, in_file_array, inout_file_array); if (result == 0) { fprintf(stderr, "files are not prepared. no test performed.\n"); exit(1); } ret = grpc_function_handle_default( &handles, MODULE_NAME "/filename_array_test"); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_default() error. (%s)\n", grpc_error_string(ret)); exit(2); } ret = grpc_call(&handles, array_size, in_file_array, inout_file_array, out_file_array); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_call() error. (%s)\n", grpc_error_string(ret)); exit(2); } ret = grpc_function_handle_destruct(&handles); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(ret)); exit(2); } ret = grpc_finalize(); if (ret != GRPC_NO_ERROR) { fprintf(stderr, "grpc_finalize() error. (%s)\n", grpc_error_string(ret)); exit(2); } result = destroy_file_names(array_size, &in_file_array, &inout_file_array, &out_file_array); if (result == 0) { fprintf(stderr, "destroying filenames failed\n"); exit(1); } return 0; }
int main(int argc, char *argv[]) { grpc_function_handle_t handles[2]; grpc_sessionid_t ids[2]; grpc_error_t result = GRPC_NO_ERROR; char *hosts[2]; long count[2]; double pi; long times, sum; int i; if (argc != 4){ fprintf(stderr, "USAGE: %s TIMES HOSTNAME1 HOSTANME2\n", argv[0]); exit(2); } hosts[0] = NULL; hosts[0] = strdup(argv[2]); hosts[1] = NULL; hosts[1] = strdup(argv[3]); if ((hosts[0] == NULL) || (hosts[1] == NULL)) { fprintf(stderr, "strdup: Can't allocate the storage for hostname.\n"); exit(2); } times = atol(argv[1]) / 2; /* Initialize */ result = grpc_initialize(config_file); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_initialize() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Initialize Function handles */ for (i = 0; i < 2; i++) { result = grpc_function_handle_init(&handles[i], hosts[i], func_name); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_init() error. (%s)\n", grpc_error_string(result)); exit(2); } } /* Asynchronous call */ for (i = 0; i < 2; i++) { result = grpc_call_async(&handles[i], &ids[i], i, times, &count[i]); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_call_async() error. (%s)\n", grpc_error_string(result)); exit(2); } } /* wait for session */ result = grpc_wait_all(); if (result != GRPC_NO_ERROR){ fprintf(stderr, "grpc_wait_all() error. (%s)\n", grpc_error_string(result)); exit(2); } /* Destruct Function handles */ for (i = 0; i < 2; i++) { result = grpc_function_handle_destruct(&handles[i]); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_function_handle_destruct() error. (%s)\n", grpc_error_string(result)); exit(2); } } /* Compute and display pi. */ for (i = 0, sum = 0; i < 2; i++) { sum += count[i]; } pi = 4.0 * (sum / ((double) times * 2)); printf("PI = %f\n", pi); /* Finalize */ result = grpc_finalize(); if (result != GRPC_NO_ERROR) { fprintf(stderr, "grpc_finalize() error. (%s)\n", grpc_error_string(result)); exit(2); } for (i = 0; i < 2; i++) { free(hosts[i]); } return 0; }