Exemple #1
0
void worker(tdata *args){
    MPI_Status status;
    part_info pi;
    proc_stat stat, total;
    int partitions = 0;

    int done = 0;

    total.result.strips = 0;
    total.result.value = 0.0;
    total.time = 0.0;

    SENDMSG(&stat, sizeof(stat), M_RANK, MSG_TAG);
    while(!done/* not all done */){
        RECVMSG(&pi, sizeof(pi), status);
        /* only recv data tags */
        if(pi.l_bound < pi.u_bound){
            SENDMSG(&stat, sizeof(stat), M_RANK, MSG_TAG);
            /* do the work */        
            stat = regproc(args->fun, pi.l_bound, pi.u_bound, args->precision, args->m);
            partitions++;
            /* printf("rank %d partition %d trapezoids %d\n", rank, partitions, stat.result.strips); */
            total.result.strips += stat.result.strips;
            total.result.value += stat.result.value;
            total.time += stat.time;

        } else {
            done = 1;
        }

    }
    /* printf("other test %d\n", rank); */

    SENDMSG(&total, sizeof(total), M_RANK, DATA_TAG);   
}
Exemple #2
0
/* 
 * manager worker scheme 
*/
void manager(tdata *args){
    MPI_Status status;
    pthread_t generator;
    proc_stat stat;
    part_info *ppi;
    part_info pi;
    double total_time = 0.0, final_result = 0.0, avg_trape = 0.0;
    int rc, flag = 0, max_trape = 0, min_trape = 0, worker_rank;

    q_part = lqopen();
    /* start a thread to do partition */
    rc = pthread_create(&generator, NULL, generate, args);
    pthread_join(generator, NULL);    

    while(flag != size - 1/* workers not all done */){
        RECVMSG(&stat, sizeof(proc_stat), status);
        if(status.MPI_TAG == MSG_TAG){    
            if(!generator_flag || NULL != lqget(q_part)){
                ppi = (part_info *)lqgetrm(q_part);
                if(NULL != ppi){
                    SENDMSG(ppi, sizeof(part_info), status.MPI_SOURCE, DATA_TAG);
                }
            } else {
                pi.l_bound = 1.0;
                pi.u_bound = 0.0;
                SENDMSG(&pi, sizeof(part_info), status.MPI_SOURCE, DATA_TAG);
            }
        } else {/* must be data tag */
            worker_rank = status.MPI_SOURCE;
            min_trape = ((min_trape > stat.result.strips || flag == 0)?stat.result.strips:min_trape);
            max_trape = ((max_trape < stat.result.strips || flag == 0)?stat.result.strips:max_trape);
            avg_trape += stat.result.strips;
            final_result += stat.result.value;
            total_time += stat.time;
            flag++;
            /* printf("test %d\n", flag); */
        }
    }
    avg_trape /= size;
    printf("avg trape: %f, max trape: %d, min trape: %d, result: %f, total time: %f\n", avg_trape, max_trape, min_trape, final_result, total_time);
    lqclose(q_part);
}
Exemple #3
0
int acl_write_fd(int fd, void *ptr, int nbytes, int send_fd)
{
	struct msghdr msg;
	struct iovec  iov[1];

#if defined(HAVE_MSGHDR_MSG_CONTROL) && !defined(MINGW)
	struct cmsghdr *cmptr;
	int *fdptr;
	union {
		struct cmsghdr cm;
	# ifdef	ACL_MACOSX
		char   control[1024];
	# else
		char   control[CMSG_SPACE(sizeof(int))];
	# endif
	} control_un;

	msg.msg_control = control_un.control;
	msg.msg_controllen = sizeof(control_un.control);

	cmptr = CMSG_FIRSTHDR(&msg);
	cmptr->cmsg_len = CMSG_LEN(sizeof(int));
	cmptr->cmsg_level = SOL_SOCKET;
	cmptr->cmsg_type = SCM_RIGHTS;

#if 0
	*((int *) CMSG_DATA(cmptr)) = send_fd;
#else
	fdptr = (int *) CMSG_DATA(cmptr);
	*fdptr = send_fd;
#endif

#else
	msg.msg_accrights = (caddr_t) &send_fd;
	msg.msg_accrightslen = sizeof(int);
#endif

	msg.msg_name = NULL;
	msg.msg_namelen = 0;

	iov[0].iov_base = ptr;
	iov[0].iov_len = nbytes;
	msg.msg_iov = iov;
	msg.msg_iovlen = 1;

	return SENDMSG(fd, &msg, 0);
}
bool OutboundConnectivity::FeedData(MSGHDR &message, double absoluteTimestamp,
		bool isAudio) {

	if (absoluteTimestamp == 0) {
		return true;
  }

#if 0
	//double rate = isAudio ? _pOutStream->GetCapabilities()->aac._sampleRate : 90000.0;
	double rate = 90000.0;
  if (isAudio) {
    BaseInStream *pPCMInStream = NULL;
    pPCMInStream = reinterpret_cast<BaseInStream*>(_pOutStream->GetStreamsManager()->FindFirstByTypeByName(ST_IN_AUDIO_PCM, QIC_STREAM_WAVE));
    StreamCapabilities *pAudioCapabilities = NULL;

    if (pPCMInStream == NULL) {
      FATAL("Inbound stream %s not found", QIC_STREAM_WAVE);
      return false;
    } else {
      pAudioCapabilities = pPCMInStream->GetCapabilities();
      if (pAudioCapabilities == NULL) {
        FATAL("Inbound stream capability %s not found", QIC_STREAM_WAVE);
        return false;
      }
    }

    rate = (CODEC_AUDIO_PCM == pAudioCapabilities->audioCodecId) ?
           pAudioCapabilities->pcm._sampleRate : _pOutStream->GetCapabilities()->aac._sampleRate;
  }

	uint32_t ssrc = isAudio ? _pOutStream->AudioSSRC() : _pOutStream->VideoSSRC();
#endif
	uint16_t messageLength = 0;
	for (uint32_t i = 0; i < (uint32_t) message.MSGHDR_MSG_IOVLEN; i++) {
		messageLength += (uint16_t) message.MSGHDR_MSG_IOV[i].IOVEC_IOV_LEN;
	}

	bool &hasTrack = isAudio ? _rtpClient.hasAudio : _rtpClient.hasVideo;
	uint32_t &packetsCount = isAudio ? _rtpClient.audioPacketsCount : _rtpClient.videoPacketsCount;
	uint32_t &bytesCount = isAudio ? _rtpClient.audioBytesCount : _rtpClient.videoBytesCount;
	uint32_t &startRTP = isAudio ? _rtpClient.audioStartRTP : _rtpClient.videoStartRTP;
	double &startTS = isAudio ? _rtpClient.audioStartTS : _rtpClient.videoStartTS;
	if (!hasTrack) {
		return true;
	}

	if (startRTP == 0xffffffff) {
		startRTP = ENTOHLP(((uint8_t *) message.MSGHDR_MSG_IOV[0].IOVEC_IOV_BASE) + 4);
		startTS = absoluteTimestamp;
	}

#if 0
/*
** temporary disable it to prevent client to enable a/v sync mechanism
** because video/audio timestamp could somehow out of sync
** it could make video or audio packets been dropped due to PTS out of range
*/
	if ((packetsCount % 500) == 0) {
		//FINEST("Send %c RTCP: %u", isAudio ? 'A' : 'V', packetsCount);
		EHTONLP(((uint8_t *) _rtcpMessage.MSGHDR_MSG_IOV[0].IOVEC_IOV_BASE) + 4, ssrc); //SSRC


		//NTP
		uint32_t integerValue = (uint32_t) (absoluteTimestamp / 1000.0);
		double fractionValue = (absoluteTimestamp / 1000.0 - ((uint32_t) (absoluteTimestamp / 1000.0)))*4294967296.0;
		uint64_t ntpVal = (_startupTime + integerValue + 2208988800ULL) << 32;
		ntpVal |= (uint32_t) fractionValue;
		EHTONLLP(_pRTCPNTP, ntpVal);

		//RTP
		uint64_t rtp = (uint64_t) (((double) (integerValue) + fractionValue / 4294967296.0) * rate);
		rtp &= 0xffffffff;
		EHTONLP(_pRTCPRTP, (uint32_t) rtp);

		//packet count
		EHTONLP(_pRTCPSPC, packetsCount);

		//octet count
		EHTONLP(_pRTCPSOC, bytesCount);
		//			FINEST("\n%s", STR(IOBuffer::DumpBuffer(((uint8_t *) _rtcpMessage.MSGHDR_MSG_IOV[0].IOVEC_IOV_BASE),
		//					_rtcpMessage.MSGHDR_MSG_IOV[0].IOVEC_IOV_LEN)));

		if (_rtpClient.isUdp) {
			SOCKET rtcpFd = isAudio ? _audioRTCPFd : _videoRTCPFd;
			sockaddr_in &rtcpAddress = isAudio ? _rtpClient.audioRtcpAddress : _rtpClient.videoRtcpAddress;
			_rtcpMessage.MSGHDR_MSG_NAME = (sockaddr *) & rtcpAddress;
			_amountSent = SENDMSG(rtcpFd, &_rtcpMessage, 0, &_dummyValue);
			if (_amountSent < 0) {
				FATAL("Unable to send message");
				return false;
			}
			ADD_OUT_BYTES_MANAGED(IOHT_UDP_CARRIER, _amountSent);
		} else {
			if (_pRTSPProtocol != NULL) {
				if (!_pRTSPProtocol->SendRaw(&_rtcpMessage,
						(uint16_t) (_rtcpMessage.MSGHDR_MSG_IOV[0].IOVEC_IOV_LEN), &_rtpClient, isAudio, false)) {
					FATAL("Unable to send raw rtcp audio data");
					return false;
				}
			}
		}
	}
#endif

	if (_rtpClient.isUdp) {
		SOCKET dataFd = isAudio ? _audioDataFd : _videoDataFd;
		sockaddr_in &dataAddress = isAudio ? _rtpClient.audioDataAddress : _rtpClient.videoDataAddress;
		message.MSGHDR_MSG_NAME = (sockaddr *) & dataAddress;
		_amountSent = SENDMSG(dataFd, &message, 0, &_dummyValue);
		if (_amountSent < 0) {
			int err = errno;
			FATAL("Unable to send message: %d; %s", err, strerror(errno));
			return false;
		}
		ADD_OUT_BYTES_MANAGED(IOHT_UDP_CARRIER, _amountSent);
	} else {
		if (_pRTSPProtocol != NULL) {
			if (!_pRTSPProtocol->SendRaw(&message, messageLength, &_rtpClient,
					isAudio, true)) {
				FATAL("Unable to send raw rtcp audio data");
				return false;
			}
		}
	}

  //INFO("send rtp data pkt %d byte cout %d", packetsCount, bytesCount);
	packetsCount++;
	bytesCount += messageLength;

	return true;
}