include/ccKVS/inline_util.h
static inline void append_responses_to_work_requests_and_delete_requests(uint16_t wr_i, struct mica_op** op_ptr_arr,
																		 struct ibv_send_wr* wr, struct mica_resp* mica_resp_arr, uint16_t* resp_buf_i,
																		 uint16_t wrkr_lid, struct ibv_sge* sgl, struct wrkr_coalesce_mica_op* response_buffer,
																		 uint8_t* requests_per_message)
{
	uint16_t i;
	uint16_t message_i = 0;
	uint8_t per_message_reqs = 0;
	for (i = 0; i < wr_i; i++) {
		if (ENABLE_ASSERTIONS) assert(op_ptr_arr[i] !=  NULL);
		op_ptr_arr[i]->opcode = 0;
		//    printf("size  is %d, it should be at most %d  \n", mica_resp_arr[i].val_len << SHIFT_BITS, HERD_PUT_REQ_SIZE);

		if (ENABLE_WORKER_COALESCING == 1) {
			if (per_message_reqs == 0) {
				wr[message_i].sg_list->length = 0;
				sgl[message_i].addr = (uintptr_t) response_buffer[(*resp_buf_i)].value;
			}
			memcpy(response_buffer[(*resp_buf_i)].value + wr[message_i].sg_list->length, mica_resp_arr[i].val_ptr,
				   (mica_resp_arr[i].val_len << SHIFT_BITS));
			wr[message_i].sg_list->length += (mica_resp_arr[i].val_len << SHIFT_BITS);
			if (ENABLE_ASSERTIONS) {
				assert(wr[message_i].sg_list->length <= sizeof(struct wrkr_coalesce_mica_op));}
			per_message_reqs++;

			if (per_message_reqs == requests_per_message[message_i]) {
				//				printf("Created message %d, with %d reqs, message length %d, payload at %llu \n", message_i, per_message_reqs,
				//							 wr[message_i].sg_list->length, response_buffer[(*resp_buf_i)].value);
				message_i++;
				per_message_reqs = 0;
				MOD_ADD_WITH_BASE((*resp_buf_i), WORKER_SS_BATCH, 0);
			}
		}
		else {
			wr[i].sg_list->length = mica_resp_arr[i].val_len << SHIFT_BITS;
			if (WORKER_ENABLE_INLINING == 1) {
				wr[i].sg_list->addr = (uint64_t) mica_resp_arr[i].val_ptr;
			} else {				if (ENABLE_ASSERTIONS) {
					if (!((*resp_buf_i) < WORKER_SS_BATCH)) {
						printf("Worker %d, resp_buf_i %d, ss_batch %d, wr_i %d, current batch size %d\n",
							   wrkr_lid, (*resp_buf_i), WORKER_SS_BATCH, i, wr_i);
						assert(0);
					}
				}
				sgl[i].addr = (uintptr_t) response_buffer[(*resp_buf_i)].value;
				memcpy(response_buffer[(*resp_buf_i)].value, mica_resp_arr[i].val_ptr, wr[i].sg_list->length);
				//       printf("Sending val_len %d\n", wr[i].sg_list->length);
				MOD_ADD_WITH_BASE((*resp_buf_i), WORKER_SS_BATCH, 0);
			}
		}
	}
}
// Have each send work request point to the MICA response and delete the corresponding request from the Request Region
Have each send work request point to the MICA response and delete the corresponding request from the Request Region
Have each send work request point to the MICA response and delete the corresponding request from the Request Region
static inline void append_responses_to_work_requests_and_delete_requests(uint16_t wr_i, struct mica_op** op_ptr_arr,
																		 struct ibv_send_wr* wr, struct mica_resp* mica_resp_arr, uint16_t* resp_buf_i,
																		 uint16_t wrkr_lid, struct ibv_sge* sgl, struct wrkr_coalesce_mica_op* response_buffer,
																		 uint8_t* requests_per_message)
{
	uint16_t i;
	uint16_t message_i = 0;
	uint8_t per_message_reqs = 0;
	for (i = 0; i < wr_i; i++) {
		if (ENABLE_ASSERTIONS) assert(op_ptr_arr[i] !=  NULL);
		op_ptr_arr[i]->opcode = 0;
		if (ENABLE_WORKER_COALESCING == 1) {
			if (per_message_reqs == 0) {
				wr[message_i].sg_list->length = 0;
				sgl[message_i].addr = (uintptr_t) response_buffer[(*resp_buf_i)].value;
			}
			memcpy(response_buffer[(*resp_buf_i)].value + wr[message_i].sg_list->length, mica_resp_arr[i].val_ptr,
				   (mica_resp_arr[i].val_len << SHIFT_BITS));
			wr[message_i].sg_list->length += (mica_resp_arr[i].val_len << SHIFT_BITS);
			if (ENABLE_ASSERTIONS) {
				assert(wr[message_i].sg_list->length <= sizeof(struct wrkr_coalesce_mica_op));}
			per_message_reqs++;
			if (per_message_reqs == requests_per_message[message_i]) {
				message_i++;
				per_message_reqs = 0;
				MOD_ADD_WITH_BASE((*resp_buf_i), WORKER_SS_BATCH, 0);
			}
		}
		else {
			wr[i].sg_list->length = mica_resp_arr[i].val_len << SHIFT_BITS;
			if (WORKER_ENABLE_INLINING == 1) {
				wr[i].sg_list->addr = (uint64_t) mica_resp_arr[i].val_ptr;
			} else {				if (ENABLE_ASSERTIONS) {
					if (!((*resp_buf_i) < WORKER_SS_BATCH)) {
						printf("Worker %d, resp_buf_i %d, ss_batch %d, wr_i %d, current batch size %d\n",
							   wrkr_lid, (*resp_buf_i), WORKER_SS_BATCH, i, wr_i);
						assert(0);
					}
				}
				sgl[i].addr = (uintptr_t) response_buffer[(*resp_buf_i)].value;
				memcpy(response_buffer[(*resp_buf_i)].value, mica_resp_arr[i].val_ptr, wr[i].sg_list->length);
				MOD_ADD_WITH_BASE((*resp_buf_i), WORKER_SS_BATCH, 0);
			}
		}
	}
}
static inline void append_responses_to_work_requests_and_delete_requests ( uint16_t wr_i , struct mica_op * * op_ptr_arr , struct ibv_send_wr * wr , struct mica_resp * mica_resp_arr , uint16_t * resp_buf_i , uint16_t wrkr_lid , struct ibv_sge * sgl , struct wrkr_coalesce_mica_op * response_buffer , uint8_t * requests_per_message ) { uint16_t i ; uint16_t message_i = 0 ; uint8_t per_message_reqs = 0 ; for ( i = 0 ; i < wr_i ; i ++ ) { if ( ENABLE_ASSERTIONS ) assert ( op_ptr_arr [ i ] != NULL ) ; op_ptr_arr [ i ] -> opcode = 0 ; if ( ENABLE_WORKER_COALESCING == 1 ) { if ( per_message_reqs == 0 ) { wr [ message_i ] . sg_list -> length = 0 ; sgl [ message_i ] . addr = ( uintptr_t ) response_buffer [ ( * resp_buf_i ) ] . value ; } memcpy ( response_buffer [ ( * resp_buf_i ) ] . value + wr [ message_i ] . sg_list -> length , mica_resp_arr [ i ] . val_ptr , ( mica_resp_arr [ i ] . val_len << SHIFT_BITS ) ) ; wr [ message_i ] . sg_list -> length += ( mica_resp_arr [ i ] . val_len << SHIFT_BITS ) ; if ( ENABLE_ASSERTIONS ) { assert ( wr [ message_i ] . sg_list -> length <= sizeof ( struct wrkr_coalesce_mica_op ) ) ; } per_message_reqs ++ ; if ( per_message_reqs == requests_per_message [ message_i ] ) { message_i ++ ; per_message_reqs = 0 ; MOD_ADD_WITH_BASE ( ( * resp_buf_i ) , WORKER_SS_BATCH , 0 ) ; } } else { wr [ i ] . sg_list -> length = mica_resp_arr [ i ] . val_len << SHIFT_BITS ; if ( WORKER_ENABLE_INLINING == 1 ) { wr [ i ] . sg_list -> addr = ( uint64_t ) mica_resp_arr [ i ] . val_ptr ; } else { if ( ENABLE_ASSERTIONS ) { if ( ! ( ( * resp_buf_i ) < WORKER_SS_BATCH ) ) { printf ( " \n " , wrkr_lid , ( * resp_buf_i ) , WORKER_SS_BATCH , i , wr_i ) ; assert ( 0 ) ; } } sgl [ i ] . addr = ( uintptr_t ) response_buffer [ ( * resp_buf_i ) ] . value ; memcpy ( response_buffer [ ( * resp_buf_i ) ] . value , mica_resp_arr [ i ] . val_ptr , wr [ i ] . sg_list -> length ) ; MOD_ADD_WITH_BASE ( ( * resp_buf_i ) , WORKER_SS_BATCH , 0 ) ; } } } }
Have each send work request point to the MICA response and delete the corresponding request from the Request Region
Have each send work request point to the MICA response and delete the corresponding request from the Request Region
//    printf("size  is %d, it should be at most %d  \n", mica_resp_arr[i].val_len << SHIFT_BITS, HERD_PUT_REQ_SIZE); //				printf("Created message %d, with %d reqs, message length %d, payload at %llu \n", message_i, per_message_reqs, //							 wr[message_i].sg_list->length, response_buffer[(*resp_buf_i)].value); //       printf("Sending val_len %d\n", wr[i].sg_list->length);