Users' Guide to NetSolve V1.4: | ||
---|---|---|
Prev | Chapter 20. Distributed Storage Infrastructure (DSI) in NetSolve | Next |
This section shows two example programs. The first program solves quick sort without using the DSI feature. The second program solves the same quick sort, but with using the dsi feature.
Figure 20-1. Example 1 (without using DSI)
int main(){ int i; int length; int* inputVec; int* outputVec; int status; printf("Enter the number of vector elements: \n"); scanf("%d", &length); inputVec = (int*)malloc(sizeof(int)*length); outputVec = (int*)malloc(sizeof(int)*length); for(i=0; i<length; i++){ printf("Element %d: ", i+1); scanf("%d", &inputVec[i]); } status = netsl("iqsort()", length, inputVec, outputVec); printf("\n\nSorted Elements: \n"); for(i=0; i<length; i++) printf("%d ", outputVec[i]); printf("\n"); return 0; } |
Figure 20-2. Example 2 (using DSI)
int main(){ int i; int length; int* inputVec; int* outputVec; int status; DSI_FILE* dsi_file; DSI_OBJECT* dvec; printf("Enter the number of vector elements: \n"); scanf("%d", &length); inputVec = (int*)malloc(sizeof(int)*length); outputVec = (int*)malloc(sizeof(int)*length); for(i=0; i<length; i++){ printf("Element %d: ", i+1); scanf("%d", &inputVec[i]); } dsi_file = ns_dsi_open("torc1.cs.utk.edu", O_CREAT|O_RDWR , 744 , 3000, IBP); if(dsi_file == NULL){ printf("error in open\n"); } dvec = ns_dsi_write_vector(dsi_file, inputVec, 10, NETSOLVE_D); if(dvec == NULL){ printf("error in write\n"); } status = netsl("iqsort()", length, dvec, outputVec); printf("\n\nSorted Elements: \n"); for(i=0; i<length; i++) printf("%d ", outputVec[i]); printf("\n"); ns_dsi_close(dsi_file); return 0; } |