static int acceptb(int card, unsigned long channel) { if(!IS_VALID_CARD(card)) { pr_debug("Invalid param: %d is not a valid card id\n", card); return -ENODEV; } if(setup_buffers(card, channel+1)) { hangup(card, channel+1); return -ENOBUFS; } pr_debug("%s: B-Channel connection accepted on channel %lu\n", sc_adapter[card]->devicename, channel+1); indicate_status(card, ISDN_STAT_BCONN, channel, NULL); return 0; }
void * rt_rtvi_init(int xsize, int ysize) { rtvihandle * handle; printf("Initializing Synergy RTVI Attached Framebuffer...\n"); handle = malloc(sizeof(rtvihandle)); handle->flip = 0; setup_buffers(); handle->scanline[0] = get_scanbuff(0); handle->scanline[1] = get_scanbuff(1); handle->xsize = xsize; handle->ysize = ysize; printf("\n"); printf("Clearing Framebuffer...\n"); rt_rtvi_clear(handle); return handle; }
static SECURITY_STATUS setup_server( struct sspi_data *data, SEC_CHAR *provider ) { SECURITY_STATUS ret; SecPkgInfoA *info; TimeStamp ttl; trace( "setting up server\n" ); ret = pQuerySecurityPackageInfoA( provider, &info ); ok( ret == SEC_E_OK, "QuerySecurityPackageInfo returned %08x\n", ret ); setup_buffers( data, info ); pFreeContextBuffer( info ); ret = pAcquireCredentialsHandleA( NULL, provider, SECPKG_CRED_INBOUND, NULL, NULL, NULL, NULL, &data->cred, &ttl ); ok( ret == SEC_E_OK, "AcquireCredentialsHandleA returned %08x\n", ret ); return ret; }
Grid::Grid() { setup_buffers(); }
int main(int argc, char **argv) { s32 result; result = SDL_Init(SDL_INIT_VIDEO); if(result) { ross_log("Failed to init SDL", LOG_ERROR); return(-1); } WindowDimension window_dimension; window_dimension.width = 800; window_dimension.height = 600; SDL_Window *window = SDL_CreateWindow("rossie", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, window_dimension.width, window_dimension.height, SDL_WINDOW_OPENGL | SDL_WINDOW_MAXIMIZED); if(window) { SDL_GLContext context = SDL_GL_CreateContext(window); if(context) { if(glewInit() == GLEW_OK) { global_running = 1; GLuint shader_program = compile_shaders(); ProgramBuffers program_buffers = setup_buffers(); glEnableClientState(GL_VERTEX_ARRAY); glViewport(0, 0, window_dimension.width, window_dimension.height); Input last_input = {}; while(global_running) { SDL_PumpEvents(); Input new_input; new_input = get_frame_input(); manage_events(new_input, window); render(new_input, last_input, shader_program, program_buffers); SDL_GL_SwapWindow(window); last_input = new_input; } } else { ross_log("Failed to init glew", LOG_ERROR); } SDL_GL_DeleteContext(context); } else { ross_log("Failed to create SDL GL context", LOG_ERROR); } } else { ross_log("Failed to create window", LOG_ERROR); } SDL_DestroyWindow(window); SDL_Quit(); return(0); }
void calc_forces(int steps) { int n, k; real tmpvec1[8], tmpvec2[8] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; /* fill the buffer cells */ if ((steps == steps_min) || (0 == steps % BUFSTEP)) setup_buffers(); send_cells(copy_cell,pack_cell,unpack_cell); /* clear global accumulation variables */ tot_pot_energy = 0.0; virial = 0.0; vir_xx = 0.0; vir_yy = 0.0; vir_zz = 0.0; vir_yz = 0.0; vir_zx = 0.0; vir_xy = 0.0; nfc++; /* clear per atom accumulation variables */ #ifdef _OPENMP #pragma omp parallel for #endif for (k=0; k<nallcells; ++k) { int i; cell *p; p = cell_array + k; for (i=0; i<p->n; ++i) { KRAFT(p,i,X) = 0.0; KRAFT(p,i,Y) = 0.0; KRAFT(p,i,Z) = 0.0; #ifdef UNIAX DREH_MOMENT(p,i,X) = 0.0; DREH_MOMENT(p,i,Y) = 0.0; DREH_MOMENT(p,i,Z) = 0.0; #endif #if defined(STRESS_TENS) PRESSTENS(p,i,xx) = 0.0; PRESSTENS(p,i,yy) = 0.0; PRESSTENS(p,i,zz) = 0.0; PRESSTENS(p,i,yz) = 0.0; PRESSTENS(p,i,zx) = 0.0; PRESSTENS(p,i,xy) = 0.0; #endif #ifndef MONOLJ POTENG(p,i) = 0.0; #endif #ifdef NNBR NBANZ(p,i) = 0; #endif #ifdef CNA if (cna) MARK(p,i) = 0; #endif #ifdef COVALENT NEIGH(p,i)->n = 0; #endif #ifdef EAM2 EAM_RHO(p,i) = 0.0; /* zero host electron density at atom site */ #ifdef EEAM EAM_P(p,i) = 0.0; /* zero host electron density at atom site */ #endif #endif } } #ifdef RIGID /* clear total forces */ if ( nsuperatoms>0 ) for(k=0; k<nsuperatoms; k++) { superforce[k].x = 0.0; superforce[k].y = 0.0; superforce[k].z = 0.0; } #endif /* What follows is the standard one-cpu force loop acting on our local data cells */ /* compute forces for all pairs of cells */ for (n=0; n<nlists; ++n) { #ifdef _OPENMP #pragma omp parallel for schedule(runtime) \ reduction(+:tot_pot_energy,virial,vir_xx,vir_yy,vir_zz,vir_yz,vir_zx,vir_xy) #endif for (k=0; k<npairs[n]; ++k) { vektor pbc; pair *P; P = pairs[n] + k; pbc.x = P->ipbc[0]*box_x.x + P->ipbc[1]*box_y.x + P->ipbc[2]*box_z.x; pbc.y = P->ipbc[0]*box_x.y + P->ipbc[1]*box_y.y + P->ipbc[2]*box_z.y; pbc.z = P->ipbc[0]*box_x.z + P->ipbc[1]*box_y.z + P->ipbc[2]*box_z.z; do_forces(cell_array + P->np, cell_array + P->nq, pbc, &tot_pot_energy, &virial, &vir_xx, &vir_yy, &vir_zz, &vir_yz, &vir_zx, &vir_xy); } } #ifdef COVALENT /* complete neighbor tables for remaining pairs of cells */ for (n=0; n<nlists; ++n) { #ifdef _OPENMP #pragma omp parallel for schedule(runtime) #endif for (k=npairs[n]; k<npairs2[n]; ++k) { vektor pbc; pair *P; P = pairs[n] + k; pbc.x = P->ipbc[0]*box_x.x + P->ipbc[1]*box_y.x + P->ipbc[2]*box_z.x; pbc.y = P->ipbc[0]*box_x.y + P->ipbc[1]*box_y.y + P->ipbc[2]*box_z.y; pbc.z = P->ipbc[0]*box_x.z + P->ipbc[1]*box_y.z + P->ipbc[2]*box_z.z; do_neightab(cell_array + P->np, cell_array + P->nq, pbc); } } #ifndef CNA /* second force loop for covalent systems */ /* does not work correctly - different threads may write to same variables #ifdef _OPENMP #pragma omp parallel for schedule(runtime) \ reduction(+:tot_pot_energy,virial,vir_xx,vir_yy,vir_zz,vir_yz,vir_zx,vir_xy) #endif */ for (k=0; k<ncells; ++k) { do_forces2(cell_array + CELLS(k), &tot_pot_energy, &virial, &vir_xx, &vir_yy, &vir_zz, &vir_yz, &vir_zx, &vir_xy); } #endif #endif /* COVALENT */ #ifndef AR /* If we don't use actio=reactio accross the cpus, we have do do the force loop also on the other half of the neighbours for the cells on the surface of the CPU */ /* compute forces for remaining pairs of cells */ for (n=0; n<nlists; ++n) { /* does not work correctly - different threads may write to same variables #ifdef _OPENMP #pragma omp parallel for schedule(runtime) #endif */ for (k=npairs[n]; k<npairs2[n]; ++k) { vektor pbc; pair *P; P = pairs[n] + k; pbc.x = P->ipbc[0]*box_x.x + P->ipbc[1]*box_y.x + P->ipbc[2]*box_z.x; pbc.y = P->ipbc[0]*box_x.y + P->ipbc[1]*box_y.y + P->ipbc[2]*box_z.y; pbc.z = P->ipbc[0]*box_x.z + P->ipbc[1]*box_y.z + P->ipbc[2]*box_z.z; /* potential energy and virial are already complete; */ /* to avoid double counting, we update only the dummy tmpvec2 */ do_forces(cell_array + P->np, cell_array + P->nq, pbc, tmpvec2, tmpvec2+1, tmpvec2+2, tmpvec2+3, tmpvec2+4, tmpvec2+5, tmpvec2+6, tmpvec2+7); } } #endif /* not AR */ #ifdef EAM2 #ifdef AR /* collect host electron density */ send_forces(add_rho,pack_rho,unpack_add_rho); #endif /* compute embedding energy and its derivative */ do_embedding_energy(); /* distribute derivative of embedding energy */ send_cells(copy_dF,pack_dF,unpack_dF); /* second EAM2 loop over all cells pairs */ for (n=0; n<nlists; ++n) { #ifdef _OPENMP #pragma omp parallel for schedule(runtime) \ reduction(+:virial,vir_xx,vir_yy,vir_zz,vir_yz,vir_zx,vir_xy) #endif for (k=0; k<npairs[n]; ++k) { vektor pbc; pair *P; P = pairs[n]+k; pbc.x = P->ipbc[0]*box_x.x + P->ipbc[1]*box_y.x + P->ipbc[2]*box_z.x; pbc.y = P->ipbc[0]*box_x.y + P->ipbc[1]*box_y.y + P->ipbc[2]*box_z.y; pbc.z = P->ipbc[0]*box_x.z + P->ipbc[1]*box_y.z + P->ipbc[2]*box_z.z; do_forces_eam2(cell_array + P->np, cell_array + P->nq, pbc, &virial, &vir_xx, &vir_yy, &vir_zz, &vir_yz, &vir_zx, &vir_xy); } } #ifndef AR /* If we don't use actio=reactio accross the cpus, we have do do the force loop also on the other half of the neighbours for the cells on the surface of the CPU */ /* compute forces for remaining pairs of cells */ for (n=0; n<nlists; ++n) { #ifdef _OPENMP #pragma omp parallel for schedule(runtime) #endif for (k=npairs[n]; k<npairs2[n]; ++k) { vektor pbc; pair *P; P = pairs[n]+k; pbc.x = P->ipbc[0]*box_x.x + P->ipbc[1]*box_y.x + P->ipbc[2]*box_z.x; pbc.y = P->ipbc[0]*box_x.y + P->ipbc[1]*box_y.y + P->ipbc[2]*box_z.y; pbc.z = P->ipbc[0]*box_x.z + P->ipbc[1]*box_y.z + P->ipbc[2]*box_z.z; /* potential energy and virial are already complete; */ /* to avoid double counting, we update only the dummy tmpvec2 */ do_forces_eam2(cell_array + P->np, cell_array + P->nq, pbc, tmpvec2, tmpvec2+1, tmpvec2+2, tmpvec2+3, tmpvec2+4, tmpvec2+5, tmpvec2+6, tmpvec2+7); } } #endif /* not AR */ #endif /* EAM2 */ /* sum up results of different CPUs */ tmpvec1[0] = tot_pot_energy; tmpvec1[1] = virial; tmpvec1[2] = vir_xx; tmpvec1[3] = vir_yy; tmpvec1[4] = vir_zz; tmpvec1[5] = vir_yz; tmpvec1[6] = vir_zx; tmpvec1[7] = vir_xy; MPI_Allreduce( tmpvec1, tmpvec2, 8, REAL, MPI_SUM, cpugrid); tot_pot_energy = tmpvec2[0]; virial = tmpvec2[1]; vir_xx = tmpvec2[2]; vir_yy = tmpvec2[3]; vir_zz = tmpvec2[4]; vir_yz = tmpvec2[5]; vir_zx = tmpvec2[6]; vir_xy = tmpvec2[7]; #ifdef AR send_forces(add_forces,pack_forces,unpack_forces); #endif }
/* * Machine-dependent startup code */ void cpu_startup(void) { vaddr_t v; vsize_t sz; vaddr_t minaddr, maxaddr; msgbuf_vaddr = PMAP_DIRECT_MAP(msgbuf_paddr); initmsgbuf((caddr_t)msgbuf_vaddr, round_page(MSGBUFSIZE)); printf("%s", version); printf("real mem = %u (%uK)\n", ctob(physmem), ctob(physmem)/1024); if (physmem >= btoc(1ULL << 32)) { extern int amdgart_enable; amdgart_enable = 1; } /* * Find out how much space we need, allocate it, * and then give everything true virtual addresses. */ sz = allocsys(0); if ((v = uvm_km_zalloc(kernel_map, round_page(sz))) == 0) panic("startup: no room for tables"); if (allocsys(v) - v != sz) panic("startup: table size inconsistency"); /* * Now allocate buffers proper. They are different than the above * in that they usually occupy more virtual memory than physical. */ setup_buffers(&maxaddr); /* * Allocate a submap for exec arguments. This map effectively * limits the number of processes exec'ing at any time. */ minaddr = vm_map_min(kernel_map); exec_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, 16*NCARGS, VM_MAP_PAGEABLE, FALSE, NULL); /* * Allocate a submap for physio */ minaddr = vm_map_min(kernel_map); phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr, VM_PHYS_SIZE, 0, FALSE, NULL); printf("avail mem = %lu (%luK)\n", ptoa(uvmexp.free), ptoa(uvmexp.free)/1024); printf("using %u buffers containing %u bytes (%uK) of memory\n", nbuf, bufpages * PAGE_SIZE, bufpages * PAGE_SIZE / 1024); bufinit(); if (boothowto & RB_CONFIG) { #ifdef BOOT_CONFIG user_config(); #else printf("kernel does not support - c; continuing..\n"); #endif } /* Safe for i/o port / memory space allocation to use malloc now. */ x86_bus_space_mallocok(); }
void calc_forces(int steps) { int n, k; real tmpvec1[5], tmpvec2[8] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; /* fill the buffer cells */ if ((steps == steps_min) || (0 == steps % BUFSTEP)) setup_buffers(); send_cells(copy_cell,pack_cell,unpack_cell); /* clear global accumulation variables */ tot_pot_energy = 0.0; virial = 0.0; vir_xx = 0.0; vir_yy = 0.0; vir_xy = 0.0; nfc++; /* clear per atom accumulation variables */ #ifdef _OPENMP #pragma omp parallel for #endif for (k=0; k<nallcells; ++k) { int i; cell *p; p = cell_array + k; for (i=0; i<p->n; ++i) { KRAFT(p,i,X) = 0.0; KRAFT(p,i,Y) = 0.0; POTENG(p,i) = 0.0; #ifdef NNBR NBANZ(p,i) = 0; #endif #if defined(STRESS_TENS) PRESSTENS(p,i,xx) = 0.0; PRESSTENS(p,i,yy) = 0.0; PRESSTENS(p,i,xy) = 0.0; #endif } } #ifdef RIGID /* clear total forces */ if ( nsuperatoms>0 ) for(k=0; k<nsuperatoms; k++) { superforce[k].x = 0.0; superforce[k].y = 0.0; } #endif /* What follows is the standard one-cpu force loop acting on our local data cells */ /* compute forces for all pairs of cells */ for (n=0; n<nlists; ++n) { #ifdef _OPENMP #pragma omp parallel for schedule(runtime) \ reduction(+:tot_pot_energy,virial,vir_xx,vir_yy,vir_xy) #endif for (k=0; k<npairs[n]; ++k) { vektor pbc; pair *P; P = pairs[n] + k; pbc.x = P->ipbc[0] * box_x.x + P->ipbc[1] * box_y.x; pbc.y = P->ipbc[0] * box_x.y + P->ipbc[1] * box_y.y; do_forces(cell_array + P->np, cell_array + P->nq, pbc, &tot_pot_energy, &virial, &vir_xx, &vir_yy, &vir_zz, &vir_yz, &vir_zx, &vir_xy); } } #ifndef AR /* If we don't use actio=reactio accross the cpus, we have do do the force loop also on the other half of the neighbours for the cells on the surface of the CPU */ /* compute forces for remaining pairs of cells */ for (n=0; n<nlists; ++n) { #ifdef _OPENMP #pragma omp parallel for schedule(runtime) #endif for (k=npairs[n]; k<npairs2[n]; ++k) { vektor pbc; pair *P; P = pairs[n] + k; pbc.x = P->ipbc[0] * box_x.x + P->ipbc[1] * box_y.x; pbc.y = P->ipbc[0] * box_x.y + P->ipbc[1] * box_y.y; /* potential energy and virial are already complete; */ /* to avoid double counting, we update only the dummy tmpvec2 */ do_forces(cell_array + P->np, cell_array + P->nq, pbc, tmpvec2, tmpvec2+1, tmpvec2+2, tmpvec2+3, tmpvec2+4, tmpvec2+5, tmpvec2+6, tmpvec2+7); } } #endif /* AR */ /* sum up results of different CPUs */ tmpvec1[0] = tot_pot_energy; tmpvec1[1] = virial; tmpvec1[2] = vir_xx; tmpvec1[3] = vir_yy; tmpvec1[4] = vir_xy; MPI_Allreduce( tmpvec1, tmpvec2, 5, REAL, MPI_SUM, cpugrid); tot_pot_energy = tmpvec2[0]; virial = tmpvec2[1]; vir_xx = tmpvec2[2]; vir_yy = tmpvec2[3]; vir_xy = tmpvec2[4]; #ifdef AR send_forces(add_forces,pack_forces,unpack_forces); #endif }
void *CallbackThread( void *userData ) { PaAlsaStream *stream = (PaAlsaStream*)userData; pthread_cleanup_push( &Stop, stream ); // Execute Stop on exit if( stream->pcm_playback ) snd_pcm_start( stream->pcm_playback ); else if( stream->pcm_capture ) snd_pcm_start( stream->pcm_capture ); while(1) { int frames_avail; int frames_got; PaStreamCallbackTimeInfo timeInfo = {0,0,0}; /* IMPLEMENT ME */ int callbackResult; int framesProcessed; pthread_testcancel(); { /* calculate time info */ snd_timestamp_t capture_timestamp; snd_timestamp_t playback_timestamp; snd_pcm_status_t *capture_status; snd_pcm_status_t *playback_status; snd_pcm_status_alloca( &capture_status ); snd_pcm_status_alloca( &playback_status ); if( stream->pcm_capture ) { snd_pcm_status( stream->pcm_capture, capture_status ); snd_pcm_status_get_tstamp( capture_status, &capture_timestamp ); } if( stream->pcm_playback ) { snd_pcm_status( stream->pcm_playback, playback_status ); snd_pcm_status_get_tstamp( playback_status, &playback_timestamp ); } /* Hmm, we potentially have both a playback and a capture timestamp. * Hopefully they are the same... */ if( stream->pcm_capture && stream->pcm_playback ) { float capture_time = capture_timestamp.tv_sec + ((float)capture_timestamp.tv_usec/1000000); float playback_time= playback_timestamp.tv_sec + ((float)playback_timestamp.tv_usec/1000000); if( fabsf(capture_time-playback_time) > 0.01 ) PA_DEBUG(("Capture time and playback time differ by %f\n", fabsf(capture_time-playback_time))); timeInfo.currentTime = capture_time; } else if( stream->pcm_playback ) { timeInfo.currentTime = playback_timestamp.tv_sec + ((float)playback_timestamp.tv_usec/1000000); } else { timeInfo.currentTime = capture_timestamp.tv_sec + ((float)capture_timestamp.tv_usec/1000000); } if( stream->pcm_capture ) { snd_pcm_sframes_t capture_delay = snd_pcm_status_get_delay( capture_status ); timeInfo.inputBufferAdcTime = timeInfo.currentTime - (float)capture_delay / stream->streamRepresentation.streamInfo.sampleRate; } if( stream->pcm_playback ) { snd_pcm_sframes_t playback_delay = snd_pcm_status_get_delay( playback_status ); timeInfo.outputBufferDacTime = timeInfo.currentTime + (float)playback_delay / stream->streamRepresentation.streamInfo.sampleRate; } } /* IMPLEMENT ME: - handle buffer slips */ /* depending on whether the host buffers are interleaved, non-interleaved or a mixture, you will want to call PaUtil_ProcessInterleavedBuffers(), PaUtil_ProcessNonInterleavedBuffers() or PaUtil_ProcessBuffers() here. */ framesProcessed = frames_avail = wait( stream ); while( frames_avail > 0 ) { //PA_DEBUG(( "%d frames available\n", frames_avail )); /* Now we know the soundcard is ready to produce/receive at least * one period. We just need to get the buffers for the client * to read/write. */ PaUtil_BeginBufferProcessing( &stream->bufferProcessor, &timeInfo, 0 /* @todo pass underflow/overflow flags when necessary */ ); frames_got = setup_buffers( stream, frames_avail ); PaUtil_BeginCpuLoadMeasurement( &stream->cpuLoadMeasurer ); callbackResult = paContinue; /* this calls the callback */ framesProcessed = PaUtil_EndBufferProcessing( &stream->bufferProcessor, &callbackResult ); PaUtil_EndCpuLoadMeasurement( &stream->cpuLoadMeasurer, framesProcessed ); /* inform ALSA how many frames we wrote */ if( stream->pcm_capture ) snd_pcm_mmap_commit( stream->pcm_capture, stream->capture_offset, frames_got ); if( stream->pcm_playback ) snd_pcm_mmap_commit( stream->pcm_playback, stream->playback_offset, frames_got ); if( callbackResult != paContinue ) break; frames_avail -= frames_got; } /* If you need to byte swap outputBuffer, you can do it here using routines in pa_byteswappers.h */ if( callbackResult != paContinue ) { stream->callback_finished = 1; stream->callbackAbort = (callbackResult == paAbort); pthread_exit( NULL ); } } /* This code is unreachable, but important to include regardless because it * is possibly a macro with a closing brace to match the opening brace in * pthread_cleanup_push() above. The documentation states that they must * always occur in pairs. */ pthread_cleanup_pop( 1 ); }
HEMesh::HEMesh(Mesh const & m_obj) : mesh(m_obj.getOpenMesh()) { setup_buffers(); }