コード例 #1
0
ファイル: main.cpp プロジェクト: fekir/samples-cpp
int main(int argc, char *argv[]){
	// Initialize the MPI environment
	if(MPI_Init( &argc, &argv ) != MPI_SUCCESS){
		MPI_Abort( MPI_COMM_WORLD, 1 );
	}

	// Get the number of processes
	int world_size;
	if(MPI_Comm_size(MPI_COMM_WORLD, &world_size) != MPI_SUCCESS){
		MPI_Abort( MPI_COMM_WORLD, 2 );
	}
	
	// Get the rank of the process
	int world_rank;
	if(MPI_Comm_rank(MPI_COMM_WORLD, &world_rank) != MPI_SUCCESS){
		MPI_Abort( MPI_COMM_WORLD, 3 );
	}

	// Get the name of the processor
	std::string processor_name(MPI_MAX_PROCESSOR_NAME, '\0');
	int name_len = processor_name.size();
	if(MPI_Get_processor_name(&processor_name[0], &name_len) != MPI_SUCCESS){
		MPI_Abort( MPI_COMM_WORLD, 4 );
	}
	processor_name.resize(name_len);

	// Print off a hello world message from every process -> normally you would send all message to the first process and print them from there
	printf("Hello world from processor \"%s\", rank %d out of %d processors\n", processor_name.c_str(), world_rank, world_size);

	// Finalize the MPI environment. No more MPI calls can be made after this
	if(MPI_Finalize() != MPI_SUCCESS){
		MPI_Abort( MPI_COMM_WORLD, 6 );
	}

	return 0;
}
コード例 #2
0
ファイル: base_proxy.cpp プロジェクト: HunterChen/BGCC
    void* call_back_thread_func(void* param) {
        BGCC_TRACE("bgcc", "enroll self");


        callback_thread_arg_t* arg = (callback_thread_arg_t*)param;
        std::string proxy_name = arg->proxy_name;
        std::string server_ip = arg->server_ip;
        int32_t server_port = arg->server_port;
        ServiceManager* service_manager = arg->service_manager;
        Semaphore* sema = arg->sema;

        SharedPointer<ClientSocket> connect;
        SharedPointer<BinaryProtocol> proto;

#ifndef _WIN32
        int32_t ep = epoll_create(1);
        struct epoll_event ee;
        struct epoll_event revents[1];

#endif
RECON:
        sema->signal();
        connect = SharedPointer<ClientSocket>(
                new(std::nothrow) ClientSocket(server_ip, server_port));

        connect->open();

        connect->set_recv_timeout(60*60*24*30);
        proto = SharedPointer<BinaryProtocol>(
                new(std::nothrow) BinaryProtocol(connect));
        int32_t ret = 0;

        ret = proto->writeMessageBegin("bgcc::BaseProcessor_enroll", "__enroll", bgcc::CALL, 0);
        if (ret < 0) {
            bgcc::TimeUtil::safe_sleep_s(1);
            goto RECON;
        }
        ret = proto->writeString(proxy_name);
        if (ret < 0) {
            bgcc::TimeUtil::safe_sleep_s(1);
            goto RECON;
        }
        ret = proto->writeMessageEnd();
        if (ret < 0) {
            bgcc::TimeUtil::safe_sleep_s(1);
            goto RECON;
        }
#ifndef _WIN32
        ee.data.fd = connect->get_socket();
        ee.events = EPOLLIN;
        epoll_ctl(ep, EPOLL_CTL_ADD, connect->get_socket(), &ee);
#endif
        while (true) {
#ifndef _WIN32
            int32_t nevent = epoll_wait(ep, revents, 1, -1);
            BGCC_TRACE("bgcc", "epoll_wait return %d", nevent);
            if (nevent >= 1) {
#endif
                char buffer[BUFSIZ];
                int32_t xxret;
                xxret = connect->read(buffer, 20);
                BGCC_TRACE("bgcc", "ret value read %d", xxret);
                if (0 != xxret) {
#ifndef _WIN32
                    epoll_ctl(ep, EPOLL_CTL_DEL, connect->get_socket(), &ee);
#endif
                    bgcc::TimeUtil::safe_sleep_s(1);
                    goto RECON;
                }
                int32_t body_len = (int32_t)ntohl(*(uint32_t*)(buffer +16));
                BGCC_TRACE("bgcc", "body size %d", body_len);
                char body[BUFSIZ];
                xxret = connect->read(body, body_len);
                BGCC_TRACE("bgcc", "body ret value read %d", xxret);
                if (0 != xxret) {
#ifndef _WIN32
                    epoll_ctl(ep, EPOLL_CTL_DEL, connect->get_socket(), &ee);
#endif
                    bgcc::TimeUtil::safe_sleep_s(1);
                    goto RECON;
                }
                int32_t processor_name_len = (int32_t)ntohl(*(uint32_t*)(body));
                std::string processor_name(body + 4, processor_name_len);
                SharedPointer<IProcessor> processor =
                    service_manager->get_service(processor_name);
                if (processor.is_valid()) {
                    processor->process(
                            body + 4 + processor_name_len,
                            body_len - 4 - processor_name_len,
                            proto);
                }

                /* added for handling unexist service*/
                else {
                    processor = service_manager->get_service("._baseservice_2012");
                    if (processor.is_valid()) {
                        SharedPointer<BinaryProtocol> bp(new BinaryProtocol(SharedPointer<ITransport>(NULL)));

                        bp->writeMessageBegin("xx", "__service_not_found", bgcc::CALL, 0);
                        bp->writeInt32(0);
                        bp->writeString("__service_not_found");
                        bp->writeBool(false);

                        void* data = NULL;
                        int32_t head_body_size;
                        NBDataBuffer* db = bp->get_data_buffer();
                        db->get_data(&data, head_body_size);
                        processor->process(
                                (char*)data + 20 + 4 + 2,
                                head_body_size - 20 - 4 - 2,
                                proto);

                    }
                }
#ifndef _WIN32
            }
#endif
        }

//#ifdef _WIN32
        return NULL;
//#endif

    }
コード例 #3
0
ファイル: process.hpp プロジェクト: dmilos/reflection
 return_type operator ()( parameter_type parameter_param )const
  {
   return processor_name()( parameter_param );
  }
コード例 #4
0
ファイル: ssl_callback_task.cpp プロジェクト: AresDice/BGCC
int32_t bgcc::SSLCallBackTask::operator()(const bool *isstopped, void *)
{
	char *pbody = _buf_body;
	int32_t ret = -1;
	char buffer[MAX_DEFAULT_LEN]={0};

	while (!(*isstopped)) {
		int32_t buffer_size=MAX_DEFAULT_LEN;
		while(((ret=_pselector->Select(_connect->ssl()))==0) && !(*isstopped));
		
		while(ret<0 && !(*isstopped)){
			bgcc::TimeUtil::safe_sleep_ms(200);
			if(Register()){
				while(((ret=_pselector->Select(_connect->ssl()))==0) && !(*isstopped));
				
				if(ret>0){
					break;
				}
			}
		}
		
		if(*isstopped){
			break;
		}
		
		if(pbody && pbody!=_buf_body){
			free(pbody);
			pbody=_buf_body;
		}

		ret = _connect->read(_buf_head, HEAD_SIZE);
		if(0!=ret){
			BGCC_WARN("bgcc", "Read ret %d errno=%d, goto reconnect", ret, BgccSockGetLastError());
			continue;
		}

		int32_t body_len = BODY_LEN(_buf_head);

		if(body_len > MAX_DEFAULT_LEN){
			if( !(pbody=(char*)calloc(1, sizeof(char) * body_len))){
				BGCC_WARN("bgcc", "Malloc failed while receiving. Size: %d", body_len);
			}
		}

		if(pbody&&(ret=_connect->read(pbody, body_len))==0){
			std::string processor_name(PROCESSOR_NAME_PTR(pbody), PROCESSOR_NAME_LEN(pbody));
			_processor=_sm->get_service(processor_name);
			if (_processor.is_valid()) {
				_processor->process(
						pbody,
						body_len,
						_proto);

				continue;
			}
		}
		else if(!pbody){
			pbody=_buf_body;
		}
		else{
			continue;
		}

		_processor = _sm->get_service(DEF_SERVICE);
		if (_processor.is_valid()) {
			if(Fake::fake_default_body(buffer, buffer_size)){
				_processor->process(buffer, buffer_size,_proto);
			}
		}
	}
	
	if(pbody && pbody!=_buf_body){
		free(pbody);
		pbody=_buf_body;
	}

	return 0;
}