cl_list* clusterization(grid *grd) { int_list *cell = NULL; cluster *parent = NULL; cl_list *current = NULL; cl_list *clusters = NULL; int k; for (k = 0; k < grd->width * grd->height; k++) { if (grd->cells[k] == SITE_OPEN) { cell = int_list_create_node(k); parent = cluster_create(cell, k < grd->width, k >= (grd->height - 1) * grd->width); // get list of clusters that contain grd->cells[k] current = find_neighbors(&clusters, grd, k); while (current != NULL) { cluster_join(&parent, &(current->item)); free(current->item); current = current->next; } cl_list_push_item(&clusters, parent); grd->cells[k] = SITE_FULL; } } return clusters; }
/** * Cluster feature vectors using linkage clustering. The function uses * the feature vectors for computing a linkage clustering * @param fa Array of prototypes * @param r Run of clustering * @return clustering structure */ cluster_t *cluster_linkage(farray_t *fa, int r) { assert(fa); double dmin; const char *mode; /* Get cluster configuration */ config_lookup_float(&cfg, "cluster.min_dist", (double *) &dmin); config_lookup_string(&cfg, "cluster.link_mode", &mode); /* Allocate cluster structure */ cluster_t *c = cluster_create(fa->len, r); /* Allocate distances */ double *dist = malloc(sizeof(double) * tria_size(fa->len)); if (!dist) { error("Could not allocate distance matrix."); return NULL; } /* Compute distances */ farray_dist_tria(fa, dist); if (verbose > 0) printf("Clustering (%s linkage) with minimum distance %4.2f.\n", mode, dmin); /* Run clustering */ cluster_murtagh(c, dist, dmin, mode[0]); free(dist); return c; }
SYMLINK3res *nfsproc3_symlink_3_svc(SYMLINK3args * argp, struct svc_req * rqstp) { static SYMLINK3res result; char *path; pre_op_attr pre; post_op_attr post; char obj[NFS_MAXPATHLEN]; int res; mode_t new_mode; PREP(path, argp->where.dir); pre = get_pre_cached(); result.status = join3(cat_name(path, argp->where.name, obj), atomic_attr(argp->symlink.symlink_attributes), exports_rw()); cluster_create(obj, rqstp, &result.status); if (argp->symlink.symlink_attributes.mode.set_it == TRUE) new_mode = create_mode(argp->symlink.symlink_attributes); else { /* default rwxrwxrwx */ new_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH; } if (result.status == NFS3_OK) { umask(~new_mode); res = backend_symlink(argp->symlink.symlink_data, obj); umask(0); if (res == -1) result.status = symlink_err(); else { result.SYMLINK3res_u.resok.obj = fh_extend_type(argp->where.dir, obj, S_IFLNK); result.SYMLINK3res_u.resok.obj_attributes = get_post_cached(rqstp); } } post = get_post_attr(path, argp->where.dir, rqstp); /* overlaps with resfail */ result.SYMLINK3res_u.resok.dir_wcc.before = pre; result.SYMLINK3res_u.resok.dir_wcc.after = post; return &result; }
RENAME3res *nfsproc3_rename_3_svc(RENAME3args * argp, struct svc_req * rqstp) { static RENAME3res result; char *from; char *to; char from_obj[NFS_MAXPATHLEN]; char to_obj[NFS_MAXPATHLEN]; pre_op_attr pre; post_op_attr post; int res; PREP(from, argp->from.dir); pre = get_pre_cached(); result.status = join(cat_name(from, argp->from.name, from_obj), exports_rw()); cluster_lookup(from_obj, rqstp, &result.status); to = fh_decomp(argp->to.dir); if (result.status == NFS3_OK) { result.status = join(cat_name(to, argp->to.name, to_obj), exports_compat(to, rqstp)); cluster_create(to_obj, rqstp, &result.status); if (result.status == NFS3_OK) { change_readdir_cookie(); res = backend_rename(from_obj, to_obj); if (res == -1) result.status = rename_err(); } } post = get_post_attr(from, argp->from.dir, rqstp); /* overlaps with resfail */ result.RENAME3res_u.resok.fromdir_wcc.before = pre; result.RENAME3res_u.resok.fromdir_wcc.after = post; result.RENAME3res_u.resok.todir_wcc.before = get_pre_cached(); result.RENAME3res_u.resok.todir_wcc.after = get_post_stat(to, rqstp); return &result; }
MKNOD3res *nfsproc3_mknod_3_svc(MKNOD3args * argp, struct svc_req * rqstp) { static MKNOD3res result; char *path; pre_op_attr pre; post_op_attr post; char obj[NFS_MAXPATHLEN]; int res; mode_t new_mode = 0; dev_t dev = 0; PREP(path, argp->where.dir); pre = get_pre_cached(); result.status = join3(cat_name(path, argp->where.name, obj), mknod_args(argp->what, obj, &new_mode, &dev), exports_rw()); cluster_create(obj, rqstp, &result.status); if (result.status == NFS3_OK) { if (argp->what.type == NF3CHR || argp->what.type == NF3BLK) res = backend_mknod(obj, new_mode, dev); /* device */ else if (argp->what.type == NF3FIFO) res = backend_mkfifo(obj, new_mode); /* FIFO */ else res = backend_mksocket(obj, new_mode); /* socket */ if (res == -1) { result.status = mknod_err(); } else { result.MKNOD3res_u.resok.obj = fh_extend_type(argp->where.dir, obj, type_to_mode(argp->what.type)); result.MKNOD3res_u.resok.obj_attributes = get_post_cached(rqstp); } } post = get_post_attr(path, argp->where.dir, rqstp); /* overlaps with resfail */ result.MKNOD3res_u.resok.dir_wcc.before = pre; result.MKNOD3res_u.resok.dir_wcc.after = post; return &result; }
int main(){ //create a Cluster WCluster* cluster = cluster_create(); //create a kThread over the cluster WkThread* kt = kThread_create(cluster); WuThread* ut; int value[100000]; for (int i=0; i< 100000; i++){ //create a uThread ut = uThread_create(false); value[i] = i; //Start the uThread over the prvoided cluster if(i%2 == 0) uThread_start(ut, cluster, (void*)run, &value[i], 0, 0); else uThread_start(ut, cluster_get_default(), (void*)run, &value[i], 0, 0); } while(uThread_get_total_number_of_uThreads() > 2) uThread_yield(); return 0; }
LINK3res *nfsproc3_link_3_svc(LINK3args * argp, struct svc_req * rqstp) { static LINK3res result; char *path, *old; pre_op_attr pre; post_op_attr post; char obj[NFS_MAXPATHLEN]; int res; PREP(path, argp->link.dir); pre = get_pre_cached(); result.status = join(cat_name(path, argp->link.name, obj), exports_rw()); cluster_create(obj, rqstp, &result.status); old = fh_decomp(argp->file); if (old && result.status == NFS3_OK) { result.status = exports_compat(old, rqstp); if (result.status == NFS3_OK) { res = backend_link(old, obj); if (res == -1) result.status = link_err(); } } else if (!old) result.status = NFS3ERR_STALE; post = get_post_attr(path, argp->link.dir, rqstp); /* overlaps with resfail */ result.LINK3res_u.resok.file_attributes = get_post_stat(old, rqstp); result.LINK3res_u.resok.linkdir_wcc.before = pre; result.LINK3res_u.resok.linkdir_wcc.after = post; return &result; }
MKDIR3res *nfsproc3_mkdir_3_svc(MKDIR3args * argp, struct svc_req * rqstp) { static MKDIR3res result; char *path; pre_op_attr pre; post_op_attr post; char obj[NFS_MAXPATHLEN]; int res; PREP(path, argp->where.dir); pre = get_pre_cached(); result.status = join3(cat_name(path, argp->where.name, obj), atomic_attr(argp->attributes), exports_rw()); cluster_create(obj, rqstp, &result.status); if (result.status == NFS3_OK) { res = backend_mkdir(obj, create_mode(argp->attributes)); if (res == -1) result.status = mkdir_err(); else { result.MKDIR3res_u.resok.obj = fh_extend_type(argp->where.dir, obj, S_IFDIR); result.MKDIR3res_u.resok.obj_attributes = get_post_cached(rqstp); } } post = get_post_attr(path, argp->where.dir, rqstp); /* overlaps with resfail */ result.MKDIR3res_u.resok.dir_wcc.before = pre; result.MKDIR3res_u.resok.dir_wcc.after = post; return &result; }
CREATE3res *nfsproc3_create_3_svc(CREATE3args * argp, struct svc_req * rqstp) { static CREATE3res result; char *path; char obj[NFS_MAXPATHLEN]; sattr3 new_attr; int fd = -1, res = -1; backend_statstruct buf; uint32 gen; int flags = O_RDWR | O_CREAT | O_TRUNC | O_NONBLOCK; PREP(path, argp->where.dir); result.status = join(cat_name(path, argp->where.name, obj), exports_rw()); cluster_create(obj, rqstp, &result.status); /* GUARDED and EXCLUSIVE maps to Unix exclusive create */ if (argp->how.mode != UNCHECKED) flags = flags | O_EXCL; if (argp->how.mode != EXCLUSIVE) { new_attr = argp->how.createhow3_u.obj_attributes; result.status = join(result.status, atomic_attr(new_attr)); } /* Try to open the file */ if (result.status == NFS3_OK) { if (argp->how.mode != EXCLUSIVE) { fd = backend_open_create(obj, flags, create_mode(new_attr)); } else { fd = backend_open_create(obj, flags, create_mode(new_attr)); } } if (fd != -1) { /* Successful open */ res = backend_fstat(fd, &buf); if (res != -1) { /* Successful stat */ if (argp->how.mode == EXCLUSIVE) { /* Save verifier in atime and mtime */ res = backend_store_create_verifier(obj, argp->how.createhow3_u. verf); } } if (res != -1) { /* So far, so good */ gen = backend_get_gen(buf, fd, obj); fh_cache_add(buf.st_dev, buf.st_ino, obj); backend_close(fd); result.CREATE3res_u.resok.obj = fh_extend_post(argp->where.dir, buf.st_dev, buf.st_ino, gen); result.CREATE3res_u.resok.obj_attributes = get_post_buf(buf, rqstp); } if (res == -1) { /* backend_fstat() or backend_store_create_verifier() failed */ backend_close(fd); result.status = NFS3ERR_IO; } } else if (result.status == NFS3_OK) { /* open() failed */ if (argp->how.mode == EXCLUSIVE && errno == EEXIST) { /* Check if verifier matches */ fd = backend_open(obj, O_NONBLOCK); if (fd != -1) { res = backend_fstat(fd, &buf); } if (res != -1) { if (backend_check_create_verifier (&buf, argp->how.createhow3_u.verf)) { /* The verifier matched. Return success */ gen = backend_get_gen(buf, fd, obj); fh_cache_add(buf.st_dev, buf.st_ino, obj); backend_close(fd); result.CREATE3res_u.resok.obj = fh_extend_post(argp->where.dir, buf.st_dev, buf.st_ino, gen); result.CREATE3res_u.resok.obj_attributes = get_post_buf(buf, rqstp); } else { /* The verifier doesn't match */ result.status = NFS3ERR_EXIST; } } } if (res == -1) { result.status = create_err(); } } /* overlaps with resfail */ result.CREATE3res_u.resok.dir_wcc.before = get_pre_cached(); result.CREATE3res_u.resok.dir_wcc.after = get_post_stat(path, rqstp); return &result; }