void parallel_floyd_warshall(int tid, int* path, 
			int start_indx, int end_indx, struct buffer buf)
{
	int i, j, k ;

	printf("Computing FW from %d to %d\n", start_indx, end_indx) ;

	for(i=start_indx ; i<end_indx ; i++)
		for(j=0 ; j<N ; j++)
			path[i*N+j] = mod(i-j);

	for (k = 0; k < N; k++)
	{
		if(tid==0) {
			call_barrier(1) ;
			if(k > 0) {
				if(remote_fd.sysm3 >= 0) {
					detach_buffer(buf, remote_fd.sysm3, 0) ;
					//attach_buffer(buf, remote_fd.sysm3, 0) ;
				}	
				if(remote_fd.dsp >= 0) {
					detach_buffer(buf, remote_fd.dsp, 0) ;
					//attach_buffer(buf, remote_fd.dsp, 0) ;
				}
			}
			call_barrier(2) ;
		}
		pthread_barrier_wait(&barrier1);
		for(i = start_indx ; i < end_indx ; i++)
			for (j = 0; j < N; j++)
				path[i*N+j] = path[i*N+j] < path[i*N+k] + path[k*N+j] ? 
					path[i*N+j] : path[i*N+k] + path[k*N+j] ;
	}
}
void a9_compute(int tid, struct buffer* buffers, int start_indx, int end_indx)
{
	histo[0] = (int*)(buffers[1].bo[0]->map) ;
	histo[1] = (int*)(buffers[2].bo[0]->map) ;
	histo[2] = (int*)(buffers[3].bo[0]->map) ;
	histo[3] = (int*)(buffers[4].bo[0]->map) ;
	histo[4] = (int*)(buffers[5].bo[0]->map) ;
	int i ;
	for(i=0 ; i<NUM_ITER ; i++)
	{
		if(tid == 0) {
			call_barrier(0) ;
			//if(i != 0) {
			//	if(remote_fd.sysm3 >= 0) attach_buffer(buffers[1], remote_fd.sysm3, 2) ; 
			//	if(remote_fd.dsp >= 0) attach_buffer(buffers[1], remote_fd.dsp, 3) ; 
			//}
			pthread_barrier_wait(&barrier0);
			compute_a9_thread1(buffers, start_indx, end_indx) ;
			if(remote_fd.sysm3 >= 0) { detach_buffer(buffers[1], remote_fd.sysm3, 0) ; }
			if(remote_fd.dsp >= 0) { detach_buffer(buffers[1], remote_fd.dsp, 0) ; }

			call_barrier(1) ;

			pthread_barrier_wait(&barrier1);

			//if(remote_fd.sysm3 >= 0) {
			//	attach_buffer(buffers[2], remote_fd.sysm3, 0) ; 
			//}
			//if(remote_fd.dsp >= 0) {
			//	attach_buffer(buffers[2], remote_fd.dsp, 0) ; 
			//}

			compute_gray_level_mapping() ;

			pthread_barrier_wait(&barrier2);

			compute_image_a9_thread1(buffers, start_indx, end_indx) ;
		} else {
			pthread_barrier_wait(&barrier0);
			compute_a9_thread2(buffers, start_indx, end_indx) ;
			if(remote_fd.sysm3 >= 0) { detach_buffer(buffers[2], remote_fd.sysm3, 0) ; }
			if(remote_fd.dsp >= 0) { detach_buffer(buffers[2], remote_fd.dsp, 0) ; }

			pthread_barrier_wait(&barrier1);
			pthread_barrier_wait(&barrier2);
			compute_image_a9_thread2(buffers, start_indx, end_indx) ;
		}
	}
}
Exemple #3
0
void TabDivePhotos::saveSubtitles()
{
	QVector<QString> selectedPhotos;
	if (!ui->photosView->selectionModel()->hasSelection())
		return;
	QModelIndexList indexes = ui->photosView->selectionModel()->selectedRows();
	if (indexes.count() == 0)
		indexes = ui->photosView->selectionModel()->selectedIndexes();
	selectedPhotos.reserve(indexes.count());
	for (const auto &photo: indexes) {
		if (photo.isValid()) {
			QString fileUrl = photo.data(Qt::DisplayPropertyRole).toString();
			if (!fileUrl.isEmpty()) {
				QFileInfo fi = QFileInfo(fileUrl);
				QFile subtitlefile;
				subtitlefile.setFileName(QString(fi.path()) + "/" + fi.completeBaseName() + ".ass");
				int offset = photo.data(Qt::UserRole + 1).toInt();
				int duration = photo.data(Qt::UserRole + 2).toInt();
				// Only videos have non-zero duration
				if (!duration)
					continue;
				struct membuffer b = { 0 };
				save_subtitles_buffer(&b, &displayed_dive, offset, duration);
				char *data = detach_buffer(&b);
				subtitlefile.open(QIODevice::WriteOnly);
				subtitlefile.write(data, strlen(data));
				subtitlefile.close();
				free(data);
			}

		}
	}
}
Exemple #4
0
int report_error(const char *fmt, ...)
{
	struct membuffer buf = { 0 };

	/* if there is no error callback registered, don't produce errors */
	if (!error_cb)
		return -1;

	VA_BUF(&buf, fmt);
	mb_cstring(&buf);
	error_cb(detach_buffer(&buf));

	return -1;
}
void parallel_kernel_reg_detect(int tid, struct buffer* buffers, int start_indx, int end_indx)
{
        int i, j, cnt ;
	int* sum_tang = (int*)(buffers[0].bo[0]->map) ;
	int* mean = (int*)(buffers[1].bo[0]->map) ;
	int* diff = (int*)(buffers[2].bo[0]->map) ;
	int* sum_diff = (int*)(buffers[3].bo[0]->map) ;
	int* tmp = (int*)(buffers[4].bo[0]->map) ;
	int* path = (int*)(buffers[5].bo[0]->map) ;

	for (i = start_indx ; i < end_indx ; i++)
		for (j = 0; j < MAXGRID; j++) {
			sum_tang[i*MAXGRID+j] = (i+1)*(j+1);
			mean[i*MAXGRID+j] = (i-j)/MAXGRID;
			path[i*MAXGRID+j] = (i*(j-1))/MAXGRID;
		}   

        for (j = start_indx ; j < end_indx ; j++)
                for (i = j; i <= MAXGRID - 1; i++)
                        for (cnt = 0; cnt <= LENGTH - 1; cnt++) {
                                diff[j*MAXGRID*LENGTH + i*LENGTH + cnt] =
                                        sum_tang[j*MAXGRID + i]; 
                        }   

        for (j = start_indx ; j < end_indx ; j++)
        {   
                for (i = j; i <= MAXGRID - 1; i++)
                {   
                        sum_diff[j*MAXGRID*LENGTH + i*LENGTH + 0] = diff[j*MAXGRID*LENGTH + i*LENGTH + 0] ;
                        for (cnt = 1; cnt <= LENGTH - 1; cnt++) {
                                sum_diff[j*MAXGRID*LENGTH + i*LENGTH + cnt] = 
                                        sum_diff[j*MAXGRID*LENGTH + i*LENGTH + cnt-1] + 
                                        diff[j*MAXGRID*LENGTH + i*LENGTH + cnt];
                        }   

                        mean[j*MAXGRID+i] = sum_diff[j*MAXGRID*LENGTH + i*LENGTH + LENGTH-1];
                }   
        }   

	if(tid == 0) {
		if(remote_fd.sysm3 >= 0) {
			detach_buffer(buffers[1], remote_fd.sysm3, 0) ;
			attach_buffer(buffers[1], remote_fd.sysm3, 0) ;
		}	
		if(remote_fd.dsp >= 0) {
			detach_buffer(buffers[1], remote_fd.dsp, 0) ;
			attach_buffer(buffers[1], remote_fd.dsp, 0) ;
		}
		call_barrier(1) ;
	}
	pthread_barrier_wait(&barrier1) ;

	int x ;
	for (j = start_indx ; j < end_indx ; j++) {
		x = 0 ;
		tmp[j*MAXGRID+j] = mean[x*MAXGRID+j] ;
		//printf("tmp[%d][%d] = %d\n", j, j, tmp[j*MAXGRID+j]) ;
		for (i = j+1; i <= MAXGRID - 1; i++) {
			x++ ;
			tmp[j*MAXGRID+i] = tmp[j*MAXGRID+i-1] + mean[x*MAXGRID+i];
			//printf("tmp[%d][%d] = %d\n", j, i, tmp[j*MAXGRID+i]) ;
		}
	}
	
	if(tid == 0) {
		if(remote_fd.sysm3 >= 0) {
			detach_buffer(buffers[4], remote_fd.sysm3, 0) ;
			attach_buffer(buffers[4], remote_fd.sysm3, 0) ;
		}	
		if(remote_fd.dsp >= 0) {
			detach_buffer(buffers[4], remote_fd.dsp, 0) ;
			attach_buffer(buffers[4], remote_fd.dsp, 0) ;
		}
		call_barrier(2) ;
	}
	pthread_barrier_wait(&barrier2) ;

	//print_array((int*)tmp) ;

	for (j = start_indx ; j < end_indx ; j++) {
		x = 0 ;
		for (i = j ; i <= MAXGRID - 1; i++) {
			path[j*MAXGRID+i] = tmp[x*MAXGRID+i] ;
			x++ ;
		}
	}
	//print_array((int*)path) ;
}