Exemplo n.º 1
0
 SharkValue* pop() {
   int size = current_state()->stack(0) == NULL ? 2 : 1;
   if (size == 2)
     xpop();
   SharkValue *value = xpop();
   assert(value && value->size() == size, "should be");
   return value;
 }
Exemplo n.º 2
0
hoc_parallel_begin() {
#if !OCSMALL
		  Symbol *sym;
        double first, last;
        char *method, *getenv();
	int parallel_hoc_main();
	int i, j;


        last = xpop();
        first = xpop();
	sym = spop();
	pushs(sym);

        method = getenv("NEURON_PARALLEL_METHOD");
        if (!method) {
                pushx(first);
                pushx(last);
                return;
        }
        if (parallel_seen++) {
                hoc_warning("Only one parallel loop per batch run allowed.",
			    "This loop is being executed serially");
                pushx(first);
                pushx(last);
                return;
        }
      
	if (!parallel_sub) { /* if 0 then master */
	    /* the master instance executes the following portion of the loop */
	    for (i = ((int)first)+1; i <= (int)last; i++) {
		char buf[10], *pnt = parallel_argv;

		/* increment pnt to "00000" */
		for (j = 0; j < 2; j++) {
		    /*EMPTY*/
		    while (*pnt++);
		}
		
		/* replace "00000" with actual value */
		sprintf(buf, "%5d", i);
		strcpy(pnt, buf);

		/* farm-out all but the first instance of the loop */
#if LINDA
		/* place arguments for eval() into tuple space, Linda
		   doesn't seem to want to let the fxn in an eval take 
		   arrays as args */
		__linda_out("parallel sargs", sargv, senvp);
 		__linda_out("parallel args", parallel_argv:sargv, parallel_envp:senvp); 
 		__linda_eval("parallel run", parallel_hoc_main(i), i);
#endif
	    }
	    
#if LINDA
	    /* do first pass though loop on master node (first to first) */
	    pushx(first);
	    pushx(first);
#else
	    /* run in serial if not LINDA */
	    pushx(first);
	    pushx(last);
#endif

	    /* block until all instances of loop have finished */
#if LINDA
	    i = (int)last - (int)first;
	    while (i-- > 0) {
		int err_val, err_num;
		
		__linda_in("parallel run", ?err_val, ?err_num);
		/* could test err_val != 0 but currently will always equal 0 */
	    }
#endif

	    /* assign value of symbol to last+1 as would be upon exiting a serial loop */
	    if (!ISARRAY(sym)) {
		if (sym->subtype == USERDOUBLE) {
		    pval = sym->u.pval;
		} else {
		    pval = OPVAL(sym);
		}
	    } else {
		if (sym->subtype == USERDOUBLE) {
		    pval = sym->u.pval + araypt(sym, SYMBOL);
		} else {
		    pval = OPVAL(sym) + araypt(sym, OBJECTVAR);	
		}
	    }
	    end_val = last + 1;

	} else {